Last active
August 15, 2020 12:32
-
-
Save AlexeySoshin/4ad1154a1fcc9e33288bc80c6dcb454b to your computer and use it in GitHub Desktop.
Part of "Build your own Future in Go" article
This file contains 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 (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