-
Notifications
You must be signed in to change notification settings - Fork 1
/
if-waitable.go
89 lines (77 loc) · 1.93 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
© 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
ISC License
*/
package parl
// 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() // similar to sync.WaitGroup.Wait()
}
// SyncWait provides sync.WaitGroup.Wait()
type SyncWait interface {
Wait()
}
// SyncWait provides sync.WaitGroup.Add()
type SyncAdd interface {
Add(delta int)
}
// SyncDone provides sync.WaitGroup.Done()
type SyncDone interface {
Done()
}
type WaitedOn interface {
SyncAdd
SyncDone
DoneBool() (isExit bool)
IsZero() (isZero bool)
}
type WaitingFor interface {
SyncAdd
IsZero() (isZero bool)
Counters() (adds, dones int)
SyncWait
String() (s string)
}
// waiter allows to use any of observable parl.WaitGroup or parl.TraceGroup
type Waiter interface {
WaitedOn
WaitingFor
}
type ErrorManager interface {
Ch() (ch <-chan GoError)
}
type ErrorSink interface {
AddError(err error)
}
type ErrorCloser interface {
InvokeIfError(addError func(err error))
Close()
}
// 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()
}