@@ -5,36 +5,46 @@ import (
5
5
)
6
6
7
7
type Context = sync.Context
8
- type WaitGroup = sync.WaitGroup
9
8
10
9
var Canceled = sync .Canceled
11
10
11
+ type WaitGroup = sync.WaitGroup
12
+
13
+ func NewWaitGroup () WaitGroup {
14
+ return sync .NewWaitGroup ()
15
+ }
16
+
17
+ // Go spawns a workflow goroutine
12
18
func Go (ctx Context , f func (ctx Context )) {
13
19
sync .Go (ctx , f )
14
20
}
15
21
16
22
type SelectCase = sync.SelectCase
17
23
24
+ // Select is the workflow-save equivalent of the select statement.
18
25
func Select (ctx Context , cases ... SelectCase ) {
19
26
sync .Select (ctx , cases ... )
20
27
}
21
28
29
+ // Await calls the provided handler when the given future is ready.
22
30
func Await [T any ](f Future [T ], handler func (Context , Future [T ])) SelectCase {
23
31
return sync .Await [T ](f , func (ctx sync.Context , f sync.Future [T ]) {
24
32
handler (ctx , f )
25
33
})
26
34
}
27
35
36
+ // Receive calls the provided handler if the given channel can receive a value. The handler receives
37
+ // the received value, and the ok flag indicating whether the value was received or the channel was closed.
28
38
func Receive [T any ](c Channel [T ], handler func (ctx Context , v T , ok bool )) SelectCase {
29
- return sync .Receive [T ](c , func (ctx sync.Context , v T , ok bool ) {
30
- handler (ctx , v , ok )
31
- })
39
+ return sync .Receive [T ](c , handler )
32
40
}
33
41
34
- func Default (handler func (Context )) SelectCase {
35
- return sync .Default (handler )
42
+ // Send calls the provided handler if the given value can be sent to the channel.
43
+ func Send [T any ](c Channel [T ], value * T , handler func (ctx Context )) SelectCase {
44
+ return sync .Send [T ](c , value , handler )
36
45
}
37
46
38
- func NewWaitGroup () WaitGroup {
39
- return sync .NewWaitGroup ()
47
+ // Default calls the given handler if none of the other cases match.
48
+ func Default (handler func (Context )) SelectCase {
49
+ return sync .Default (handler )
40
50
}
0 commit comments