-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathall_example_test.go
More file actions
39 lines (36 loc) · 842 Bytes
/
all_example_test.go
File metadata and controls
39 lines (36 loc) · 842 Bytes
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
package flowmatic_test
import (
"context"
"fmt"
"time"
"github.com/carlmjohnson/flowmatic"
)
func ExampleAll() {
ctx := context.Background()
start := time.Now()
err := flowmatic.All(ctx,
func(ctx context.Context) error {
// This task sleeps then returns an error
d := 1 * time.Millisecond
time.Sleep(d)
fmt.Println("slept for", d)
return fmt.Errorf("abort after %v", d)
},
func(ctx context.Context) error {
// sleepFor is a cancelable time.Sleep.
// The error of first task
// causes the early cancelation of this one.
if !sleepFor(ctx, 1*time.Minute) {
fmt.Println("canceled")
}
return nil
},
)
fmt.Println("err:", err)
fmt.Println("exited early?", time.Since(start) < 10*time.Millisecond)
// Output:
// slept for 1ms
// canceled
// err: abort after 1ms
// exited early? true
}