Skip to content

Commit bab60a5

Browse files
committed
docs tweak
1 parent b2a8c6d commit bab60a5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

internal/util/eventual.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff 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.
1515
type 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)

0 commit comments

Comments
 (0)