Context
#struct ContextA context.
| Name | Type | Description |
|---|---|---|
state | i64* | The internal state: cancelled, the deadline and whether there is one. |
parent | Context* | The parent context, or null for the root. |
mu | sync.Mutex | The lock every context in one tree shares. |
cv | sync.CondVar | The condition variable that cancellation wakes. |
is_root | bool = false | Whether this context is the root. |
import ctx
func main:
root := ctx.Background()
cancellable := ctx.WithCancel(root)
timed := ctx.WithTimeout(cancellable, 30)
println ctx.IsDone(timed),
"[" + ctx.Err(timed) + "]",
ctx.Deadline(timed) > 0,
ctx.Deadline(root)
println ctx.Wait(timed, 10)
println ctx.Wait(timed, 1000), ctx.Err(timed)
ctx.Cancel(cancellable)
println ctx.IsDone(cancellable), ctx.Err(cancellable), ctx.IsDone(root)
past := ctx.WithDeadline(root, 1)
println ctx.IsDone(past), ctx.Err(past)
ctx.Free(past)
ctx.Free(timed)
ctx.Free(cancellable)
ctx.Free(root)
endfalse [] true 0 false true deadline exceeded true cancelled false true deadline exceeded