-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmany_example_test.go
More file actions
59 lines (51 loc) · 1.28 KB
/
many_example_test.go
File metadata and controls
59 lines (51 loc) · 1.28 KB
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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package task
import (
"context"
"errors"
"fmt"
"time"
)
func ExampleIter() {
e := errors.New("err")
a := func(_ context.Context) error { fmt.Println("a"); return nil }
b := func(_ context.Context) error { fmt.Println("b"); return e }
c := func(_ context.Context) error { fmt.Println("c"); return nil }
err := Iter(a, b, c).Run(context.Background())
if err != e {
fmt.Println("unexpected error:", err)
return
}
// output: a
// b
}
func ExampleSkip() {
e := errors.New("err")
a := func(ctx context.Context) error {
if err := Sleep(time.Minute).Run(ctx); err != nil {
fmt.Println("context canceled")
return err
}
fmt.Println("a")
return nil
}
b := func(_ context.Context) error { fmt.Println("b"); return e }
c := func(ctx context.Context) error {
if err := Sleep(time.Minute).Run(ctx); err != nil {
fmt.Println("context canceled")
return err
}
fmt.Println("c")
return nil
}
err := Skip(a, b, c).Run(context.Background())
if err != e {
fmt.Println("unexpected error:", err)
return
}
// output: b
// context canceled
// context canceled
}