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 func (v *Value) Lock() {
33 func (v *Value) Unlock() {
37 // Close closes the value. This can never fail. For a definition of
38 // "close" see the struct docs.
39 func (w *Value) Close() error {
44 // If we haven't set the value, set it
53 // Value returns the value that was set.
54 func (w *Value) Value() interface{} {
58 // If we already have a value just return
60 // No value, setup the condition variable if we have to
62 w.cond = sync.NewCond(&w.lock)
73 // SetValue sets the value.
74 func (w *Value) SetValue(v interface{}) {
82 // If we have a condition, clear it