futures

package
v0.0.0-...-630fae4 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2015 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package futures is useful for broadcasting an identical message to a multitude of listeners as opposed to channels which will choose a listener at random if multiple listeners are listening to the same channel. The future will also cache the result so any future interest will be immediately returned to the consumer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Completer

type Completer <-chan interface{}

Completer is a channel that the future expects to receive a result on. The future only receives on this channel.

type Future

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

Future represents an object that can be used to perform asynchronous tasks. The constructor of the future will complete it, and listeners will block on getresult until a result is received. This is different from a channel in that the future is only completed once, and anyone listening on the future will get the result, regardless of the number of listeners.

func New

func New(completer Completer, timeout time.Duration) *Future

New is the constructor to generate a new future. Pass the completed item to the toComplete channel and any listeners will get notified. If timeout is hit before toComplete is called, any listeners will get passed an error.

func (*Future) GetResult

func (f *Future) GetResult() (interface{}, error)

GetResult will immediately fetch the result if it exists or wait on the result until it is ready.

Jump to

Keyboard shortcuts

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