-
Notifications
You must be signed in to change notification settings - Fork 1
/
if-waitable.go
47 lines (42 loc) · 1.31 KB
/
if-waitable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
© 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
ISC License
*/
package parl
import "context"
// Waitable is the invoker’s Wait part of sync.WaitGroup and
// other implementations.
// Waitable is a many-to-many relation.
// Waitable allows the caller to await exit and free of all invocations.
// waitsForLots parl.WaitGroup
// shutsDownLots parl.OnceChan
// … = NewSomething(&waitsForLots, &shutsDownLots)
// go someThread(&waitsForLots, &shutsDownLots)
// func someThread(Doneable w, context.Context ctx) {
// defer w.Done()
// w.Add(2)
// go somethingElse()
type Waitable interface {
Wait()
}
// Doneable is the callee part of sync.Waitgroup
// and other implementations
// Doneable is a many-to-many relation.
// Doneable allows the callee to instatiate and invoke any number
// of things that are awaitable by the caller.
// … = NewSomething(&waitsForLots, &shutsDownLots)
// go someThread(&waitsForLots, &shutsDownLots)
// func someThread(Doneable w, context.Context ctx) {
// defer w.Done()
// w.Add(2)
// go somethingElse()
type Doneable interface {
Add(delta int)
Done()
}
// context.WithCancel provides a thread-safe race-free idempotent
// many-to-many shutdown relation.
type CancelContext interface {
context.Context
Cancel()
}