8 // ErrClosed is returned by any closed values.
10 // A "closed value" is when the shadow has been notified that the real
11 // side is complete and any blocking values will _never_ be satisfied
12 // in the future. In this case, this error is returned. If a value is already
13 // available, that is still returned.
14 var ErrClosed = errors.New("shadow closed")
16 // Value is a struct that coordinates a value between two
17 // parallel routines. It is similar to atomic.Value except that when
18 // Value is called if it isn't set it will wait for it.
20 // The Value can be closed with Close, which will cause any future
21 // blocking operations to return immediately with ErrClosed.
29 // Close closes the value. This can never fail. For a definition of
30 // "close" see the struct docs.
31 func (w *Value) Close() error {
36 // If we haven't set the value, set it
45 // Value returns the value that was set.
46 func (w *Value) Value() interface{} {
50 // If we already have a value just return
52 // No value, setup the condition variable if we have to
54 w.cond = sync.NewCond(&w.lock)
65 // SetValue sets the value.
66 func (w *Value) SetValue(v interface{}) {
74 // If we have a condition, clear it