future

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: AGPL-3.0, ISC Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTimeout

func WithTimeout(parent context.Context, timeout time.Duration) context.Context

WithTimeout applies a timeout for the future value getter.

Types

type Future

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

func New

func New() *Future

New is Future constructor.

func (*Future) C

func (f *Future) C() <-chan Value

C returns the channel on which the future value is to be set. Use instead of Get in case a more controlled select clause needs to be implemented.

Note that a value can be extracted only once (compared to Get where the set value can be read multiple times). After a value has been extracted, the channel is closed.

func (*Future) Err

func (f *Future) Err() error

Err returns an error that has occurred while value readout.

func (*Future) Get

func (f *Future) Get(ctx context.Context) (Value, bool)

Get returns the future Value along with status flag, whether the returned value is valid (has been set). Note that a nil Value might be also valid.

Get blocks by default until a value has been set. However, WithTimeout can be used to modify the behaviour, as following:

  • in case of a negative timeout value, Get will block as if the context wouldn't have been modified;
  • in case the set timeout is 0 (zero), Get will return immediately no matter whether a Value has been set, or not;
  • in case of a positive timeout value, Get will return on a set future Value or when the timeout expires (depending on witch one is triggered first);

See Future.Err for more info in case the status is set to false.

func (*Future) Set

func (f *Future) Set(v Value)

Set sets the future value, witch can be read/extracted via Get.

Note that a value can only be set once. Any sequential attempts will be ignored

type Value

type Value interface{}

Jump to

Keyboard shortcuts

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