-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples_test.go
More file actions
42 lines (34 loc) · 788 Bytes
/
examples_test.go
File metadata and controls
42 lines (34 loc) · 788 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
40
41
42
package timeout_test
import (
"errors"
"fmt"
"time"
"atomicgo.dev/timeout"
)
func Example_timeoutReached() {
res, err := timeout.Execute(time.Second*1, func() (string, error) {
time.Sleep(time.Second * 2)
return "Hello, World!", nil
})
fmt.Println(res, err)
// Output:
// timeout reached
}
func Example_timeoutNotReached() {
res, err := timeout.Execute(time.Second*2, func() (string, error) {
time.Sleep(time.Second * 1)
return "Hello, World!", nil
})
fmt.Println(res, err)
// Output:
// Hello, World! <nil>
}
func Example_timeoutWithError() {
res, err := timeout.Execute(time.Second*2, func() (string, error) {
time.Sleep(time.Second * 1)
return "", errors.New("some error") //nolint: goerr113
})
fmt.Println(res, err)
// Output:
// some error
}