future

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: Apache-2.0 Imports: 4 Imported by: 6

Documentation

Overview

Package future implements a generic future handling system.

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = errors.New("future canceled")

ErrCanceled is returned by Wait if the future gets canceled while waiting.

View Source
var ErrTimeout = errors.New("future timeout")

ErrTimeout is returned by Wait if the specified timeout is exceeded.

Functions

This section is empty.

Types

type Future

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

A Future is a low-level future type that can be extended to transport custom information.

func New

func New() *Future

New will return a new Future.

func (*Future) Attach added in v0.14.0

func (f *Future) Attach(f2 *Future)

Attach will attach the specified future to this future. If this future is completed or cancelled, all attached futures will be completed or cancelled as well. If this future has already been completed or cancelled the specified future is completed or cancelled immediately.

func (*Future) Cancel

func (f *Future) Cancel(result interface{}) bool

Cancel will cancel the future.

func (*Future) Complete

func (f *Future) Complete(result interface{}) bool

Complete will complete the future.

func (*Future) Result added in v0.13.1

func (f *Future) Result() interface{}

Result will return the value provided when the future has been completed or cancelled.

func (*Future) Wait

func (f *Future) Wait(timeout time.Duration) error

Wait will wait the given amount of time and return whether the future has been completed, canceled or the request timed out. If no time has been provided the wait will never time out.

type Store

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

A Store is used to store futures.

func NewStore

func NewStore() *Store

NewStore will create a new Store.

func (*Store) All

func (s *Store) All() []*Future

All will return a slice with all stored futures.

func (*Store) Await

func (s *Store) Await(timeout time.Duration) error

Await will wait until all futures have completed or cancelled, or the timeout has been reached.

func (*Store) Clear

func (s *Store) Clear()

Clear will cancel all stored futures and remove them if the store is unprotected.

func (*Store) Delete

func (s *Store) Delete(id packet.ID)

Delete will remove a future from the store.

func (*Store) Get

func (s *Store) Get(id packet.ID) *Future

Get will retrieve a future from the store.

func (*Store) Protect

func (s *Store) Protect(value bool)

Protect will set the protection attribute and if true prevents the store from being cleared.

func (*Store) Put

func (s *Store) Put(id packet.ID, future *Future)

Put will save a future to the store.

Jump to

Keyboard shortcuts

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