3 ms·
var ( ch = make(chan *http.Response) err error ) .... return func() (*http.Response, error) { return <-ch, err
by bkirwi 12y ago
var (
ch = make(chan *http.Response)
err error
)
....
return func() (*http.Response, error) {
return <-ch, err
}
It seems to me like calling that returned function is destructive -- if you block on it more than one, it would block forever. Is that right? It seems like a different contract than the usual Future / Promise shtick.
- bsaul 12y agoYes, i wondered the same. The trick is that it relies on creating a waitgroup prior to that, and passing it as a parameter to the "future". You wait on that group, and only then will you be able to be sure that you're not going to wait when looking at the result of the promise.