Created
August 24, 2017 16:25
-
-
Save jonbodner/ef1d328c2906638c0bc7e6f569d6838f to your computer and use it in GitHub Desktop.
future-blog-post-9
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
func main() { | |
a := 10 | |
f := future.New(func() (interface{}, error) { | |
return doSomethingThatTakesAWhile(a) | |
}) | |
// this will wait for a second to complete | |
// and will return nil for both val and err | |
// and timeout will be true | |
val, timeout, err := f.GetUntil(1 * time.Second) | |
fmt.Println(val, timeout, err) | |
// this will wait for val and err to have values | |
val, err = f.Get() | |
fmt.Println(val, err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment