safe

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

package safe provides a thread-safe holder for a value that may be updated by multiple goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Safe

type Safe struct {
	// contains filtered or unexported fields
}

Safe contains a thread-safe value, also allowing getters to wait until the value is non-nil.

func New

func New(value interface{}) *Safe

New create a new Safe instance given a value

func (*Safe) Get

func (s *Safe) Get() interface{}

Get returns the value, even if nil.

func (*Safe) GetWhenDefined

func (s *Safe) GetWhenDefined() interface{}

GetWhenDefined returns the value, waiting until the value is not nil.

func (*Safe) Put

func (s *Safe) Put(value interface{})

Put sets a new value, which may be nil. If non-nil, any getters waiting via GetWhenDefined will wake up with the new value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL