This is an experiment to see how Go handles chaining channels together. If a channel is returning a value taken from a second channel, does it take the value from the second one when it stops blocking, or when it begins to block?
Say we have the (syntactically valid!) Go code:
x <- <- y
which passes a value from channel y
onto a channel x
.
Let's also say that channel y
already has a value on it.
We're interested in having someone eventually read from channel 'x', but controlling whatever value is on it from somewhere else. One use case for this might be a channel which blocks to put values onto, but returns a default value (populated by some goroutine) if the channel would otherwise be empty. This would give us a channel which would block feeding it new values, but would return a default value rather than blocking when reading from it if empty.
We're going to read from channel x
, which is blocking. Before we do, we change the value on channel y
.
If we get the updated value on y
, then we know that the values served by the first value are taken from the second only after blocking. If not, it should reach a deadlock.
Similar topic, when the value is evaluated?