future

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

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 {
	Data *sync.Map
	// 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) Bind

func (f *Future) Bind(f2 *Future)

Bind will tie the current future to the specified future. If the bound to future is completed or canceled the current will as well. Data saved in the bound future is copied to the current on complete and cancel.

func (*Future) Cancel

func (f *Future) Cancel()

Cancel will cancel the future.

func (*Future) Complete

func (f *Future) Complete()

Complete will complete the future.

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.

type Store

type Store struct {
	sync.RWMutex
	// 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 and removed or timeout is 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