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

NameTypeDescription
newboolReplacement 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()) }
Go Reference