-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
51 lines (40 loc) · 891 Bytes
/
example_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
package future_test
import (
"fmt"
"github.com/dancantos/future"
)
func ExampleGo() {
longRunningTask := func() string {
return "Hello World"
}
value := future.Go(longRunningTask)
fmt.Println(value.Get())
// Output: Hello World
}
func ExampleGoErr() {
longRunningError := func() (string, error) {
return "", fmt.Errorf("Bad things")
}
value := future.GoErr(longRunningError)
fmt.Println("value:" + value.Get().Value)
fmt.Println("err: " + value.Get().Err.Error())
// Output: value:
// err: Bad things
}
func Example() {
long1 := func() string {
return "input2"
}
long2 := func(string) (int, error) {
return 1, nil
}
future1 := future.Go(long1)
future2 := future.GoErr(func() (int, error) {
return long2(future1.Get())
})
if future2.Get().Err != nil {
fmt.Println("uh oh")
}
fmt.Printf("value: %d\n", future2.Get().Value)
// Output: value: 1
}