Re: [go-nuts] Implementing futures with channels [was: How to pass a value...]

2017-10-18 Thread 'Axel Wagner' via golang-nuts
What you are doing is what sync.Once was invented for: https://play.golang.org/p/erZqwFYgIR On Tue, Oct 17, 2017 at 11:37 PM, Juliusz Chroboczek wrote: > > The answer depends on whether you have just one value or many. For a > single > > value (sometimes known as a "future"), I tend to pair a ch

[go-nuts] Implementing futures with channels [was: How to pass a value...]

2017-10-17 Thread Juliusz Chroboczek
> The answer depends on whether you have just one value or many. For a single > value (sometimes known as a "future"), I tend to pair a chan of struct{} > with a value to be set. To make the value available, set it, then close the > channel. Readers wait on the channel, then read the value. That's