Standard library / sync/atomic

atomic.Value.Store()

Publish a non-nil value of the same concrete type as prior stores. Mutable objects still need protection. Expected stdout: 'second\n'.

Formal Syntax & Structure

go syntaxgo
func (v *Value) Store(val any)

Parameters & Attributes

NameTypeDescription
valanyValue to store; context values should be request-scoped.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sync/atomic")
func main() { var v atomic.Value; v.Store("first"); v.Store("second"); fmt.Println(v.Load()) }
Go Reference