File tree 1 file changed +10
-2
lines changed
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ var ErrFutureCanceled = errors.New("future canceled")
30
30
// Many simultaneous listeners may wait for result either with `f.Value()`
31
31
// or by selecting/fetching from `f.WaitChan()`, which is closed when future
32
32
// fulfilled.
33
+ // Selectable contains sync.Mutex, so it is not movable/copyable.
33
34
type Selectable struct {
34
35
m sync.Mutex
35
36
val interface {}
@@ -39,12 +40,17 @@ type Selectable struct {
39
40
}
40
41
41
42
// NewSelectable returns new selectable future.
43
+ // Note: this method is for backward compatibility.
44
+ // You may allocate it directly on stack or embedding into larger structure
42
45
func NewSelectable () * Selectable {
43
- return & Selectable {wait : make ( chan struct {}) }
46
+ return & Selectable {}
44
47
}
45
48
46
49
func (f * Selectable ) wchan () <- chan struct {} {
47
50
f .m .Lock ()
51
+ if f .wait == nil {
52
+ f .wait = make (chan struct {})
53
+ }
48
54
ch := f .wait
49
55
f .m .Unlock ()
50
56
return ch
@@ -77,7 +83,9 @@ func (f *Selectable) Fill(v interface{}, e error) error {
77
83
atomic .StoreUint32 (& f .filled , 1 )
78
84
w := f .wait
79
85
f .wait = closed
80
- close (w )
86
+ if w != nil {
87
+ close (w )
88
+ }
81
89
}
82
90
f .m .Unlock ()
83
91
return f .err
You can’t perform that action at this time.
0 commit comments