Standard library / sync/atomic
atomic.Bool.Swap()
Set the boolean and return the previous value. Expected stdout: 'false true\n'.
Formal Syntax & Structure
go syntaxgo
func (x *Bool) Swap(new bool) (old bool)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| new | bool | Replacement value. |
Return Value
(old bool)
Previous boolean.
Working Example
Example Snippetgo
package main
import ( "fmt" "sync/atomic")
func main() { var x atomic.Bool; fmt.Println(x.Swap(true), x.Load()) }