atomics

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2016 License: MPL-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package atomics provides types that can be concurrently accessed and modified, without caller code needing to implement locking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

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

Bool is an atomic boolean, no need for locking which makes the code faster and simpler.

This interface is really just to abstract away the 0 or 1 value of an int32 modified using the sync/atomic package. Hopefully the go compiler will inline these methods so they'll be super fast.

func NewBool

func NewBool(value bool) Bool

NewBool returns an atomics.Bool initialized with value.

Note it is perfectly safe to just declare an atomics.Bool; it defaults to false just like a normal boolean would do.

func (*Bool) Get

func (b *Bool) Get() bool

Get returns the value of the boolean

func (*Bool) Set

func (b *Bool) Set(value bool)

Set sets the value of the boolean to true or false

func (*Bool) Swap

func (b *Bool) Swap(value bool) bool

Swap sets the value of the boolean to true or false and returns the old value

type Once

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

Once is similar to sync.Done except that once.Do() returns true, if this was the first call to once.Do(). Additionally a method once.Wait() have been added for anyone waiting for this once.Do() to have been called.

Also once.Do(nil) will not panic, but act similar to once.Do(func(){}).

func (*Once) Do

func (o *Once) Do(f func()) bool

Do will call f() and return true, the first time once.Do() is called. All following callls to once.Do() will not call f() and return false.

func (*Once) Wait

func (o *Once) Wait()

Wait will block until once.Do() have been called once. After this once.Wait() will always return immediately.

Jump to

Keyboard shortcuts

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