File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,12 @@ import (
66 "github.com/10gen/migration-verifier/option"
77)
88
9- // Eventual represents a value that isn’t available when this struct is created
10- // but can be awaited via a channel.
9+ // Eventual solves the “one writer, many readers” problem: a value gets
10+ // written once, then the readers will see that the value is `Ready()` and
11+ // can then `Get()` it.
1112//
12- // This is much like how context.Context’s Done() and Err() methods work.
13- // It’s useful to await a value’s readiness via channel but then read it
14- // multiple times.
13+ // It’s like how `context.Context`’s `Done()` and `Err()` methods work, but
14+ // generalized to any data type.
1515type Eventual [T any ] struct {
1616 ready chan struct {}
1717 val option.Option [T ]
@@ -47,9 +47,11 @@ func (e *Eventual[T]) Set(val T) {
4747 defer e .mux .Unlock ()
4848
4949 if e .val .IsSome () {
50- panic ("Double set on eventual!" )
50+ panic ("Tried to set an eventual twice !" )
5151 }
5252
53+ // NB: This *must* happen before the close(), or else a fast reader may
54+ // not see this value.
5355 e .val = option .Some (val )
5456
5557 close (e .ready )
You can’t perform that action at this time.
0 commit comments