-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_example_test.go
More file actions
34 lines (30 loc) · 981 Bytes
/
context_example_test.go
File metadata and controls
34 lines (30 loc) · 981 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
package core_test
import (
. "dappco.re/go"
)
// ExampleBackground creates a background context through `Background` for request lifetime
// control. Cancellation and timeout lifetimes are created through the core context
// surface.
func ExampleBackground() {
ctx := Background()
Println(ctx.Err() == nil)
// Output: true
}
// ExampleWithTimeout creates a timeout context through `WithTimeout` for request lifetime
// control. Cancellation and timeout lifetimes are created through the core context
// surface.
func ExampleWithTimeout() {
ctx, cancel := WithTimeout(Background(), 50*Millisecond)
defer cancel()
Println(ctx.Err() == nil)
// Output: true
}
// ExampleWithCancel creates a cancellable context through `WithCancel` for request
// lifetime control. Cancellation and timeout lifetimes are created through the core
// context surface.
func ExampleWithCancel() {
ctx, cancel := WithCancel(Background())
cancel()
Println(ctx.Err() != nil)
// Output: true
}