Skip to content

Instantly share code, notes, and snippets.

@AlexeySoshin
Last active August 15, 2020 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexeySoshin/4ad1154a1fcc9e33288bc80c6dcb454b to your computer and use it in GitHub Desktop.
Save AlexeySoshin/4ad1154a1fcc9e33288bc80c6dcb454b to your computer and use it in GitHub Desktop.
Part of "Build your own Future in Go" article
func (this *future[T]) Get() Result[T] {
if this.completed {
return this.result
} else {
fmt.Println("Need to wait...")
select {
case <-this.wait:
return this.result
case <-this.ctx.Done():
return &result(T){failure: this.ctx.Err()}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment