Created
August 24, 2017 16:29
-
-
Save jonbodner/20e07228ebd52b90c57d54bcffbe64ab to your computer and use it in GitHub Desktop.
future-blog-post-10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Interface represents a future. No concrete implementation is | |
// exposed; all access to a future is via this interface. | |
type Interface interface { | |
// Get returns the values calculated by the future. It will pause until | |
// the value is calculated. | |
// | |
// If Get is invoked multiple times, the same value will be returned each time. | |
// Subsequent calls to Get will return instantaneously. | |
Get() (interface{}, error) | |
// GetUntil waits for up to Duration d for the future to complete. If the | |
// future completes before the Duration completes, the value and error are returned | |
// and timeout is returned as false. If the Duration completes before the future | |
// returns, nil is returned for the value and the error and timeout is returned | |
// as true. | |
GetUntil(d time.Duration) (interface{}, bool, error) | |
// Then allows multiple function calls to be chained together into a | |
// single future. | |
// | |
// Each call is run in order, with the output of the previous call passed into | |
// the next function in the chain. If an error occurs at any step in the chain, | |
// processing ceases and the error is returned via Get or GetUntil. | |
Then(Step) Interface | |
} | |
type Step func(interface{}) (interface{}, error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment