generated from moul/golang-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpattern_test.go
66 lines (56 loc) · 1.07 KB
/
pattern_test.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
package u_test
import (
"fmt"
"net/http"
"testing"
"time"
"moul.io/u"
)
func ExampleCombineFuncs() {
cleanup := func() { fmt.Print("A") }
cleanup = u.CombineFuncs(cleanup, func() { fmt.Print("B") })
cleanup = u.CombineFuncs(func() { fmt.Print("C") }, cleanup)
cleanup()
// Output: CAB
}
func ExampleCheckErr() {
_, err := http.Get("http://foo.bar")
u.CheckErr(err) // panic
}
func ExampleFuture() {
future := u.Future(func() (interface{}, error) {
time.Sleep(100 * time.Millisecond)
return "foobar", nil
})
// here, we can do some stuff
ret := <-future
fmt.Println("Ret:", ret.Ret)
fmt.Println("Err:", ret.Err)
// Output:
// Ret: foobar
// Err: <nil>
}
func BenchmarkCombineFuncs(b *testing.B) {
f1 := func() {}
f2 := func() {
fmt.Println("A")
}
f3 := func() {
fmt.Println("B")
fmt.Println("C")
fmt.Println("D")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
u.CombineFuncs(f1, f2, f3)
}
}
func BenchmarkFuture(b *testing.B) {
f1 := func() (interface{}, error) {
return nil, nil
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
u.Future(f1)
}
}