Background / WithCancel / WithTimeout; Done is a chan. No WithValue.
struct Context
pub struct Context {
pub done chan int
pub deadline_ns int
pub keys []string
pub vals []string
}
Purpose
Public struct `Context`.
Parameters
done chan int- field (channel; type chan int)
deadline_ns int- field (int)
keys []string- field ([]string)
vals []string- field ([]string)
background
pub fn background() Context
Purpose
background; returns Context.
Parameters
none
Returns
Context — a value of this type
with_cancel
pub fn with_cancel() Cancel
Purpose
Derive a new value with cancel.
Parameters
none
Returns
Cancel — a value of this type
with_cancel_parent
pub fn with_cancel_parent(parent &Context) Cancel
Purpose
with_cancel_parent is the parent-aware form of with_cancel. The returned context shares the parent's deadline and is canceled when the parent's Done channel closes. Parent and child Cancel values can still be canceled explicitly; close_once makes all three paths idempotent.
Parameters
parent &Context- parent (borrowed; caller keeps it; type &Context)
Returns
Cancel — a value of this type
with_timeout
pub fn with_timeout(timeout_ns int) Cancel
Purpose
Derive a new value with timeout.
Parameters
timeout_ns int- timeout in nanoseconds (int)
Returns
Cancel — a value of this type
with_deadline
pub fn with_deadline(deadline_ns int) Cancel
Purpose
Derive a new value with deadline.
Parameters
deadline_ns int- deadline_ns (int)
Returns
Cancel — a value of this type
(Context) deadline
pub fn (c Context) deadline() int
Purpose
Call `deadline` on `Context`.
Parameters
c Context- receiver Context (value receiver)
Returns
int — a value of this type
err
pub fn err(c &Context) int
Purpose
err; returns int. Throws on failure.
Parameters
c &Context- byte or character code (borrowed; caller keeps it; type &Context)
Returns
int — a value of this type
with_value
pub fn with_value(parent &Context, key string, val string) Context
Purpose
with_value attaches a string key/value ( WithValue; v1 keys and values are strings, not any). Later with_value of the same key shadows earlier ones.
Parameters
parent &Context- parent (borrowed; caller keeps it; type &Context)
key string- key (string)
val string- value (string)
Returns
Context — a value of this type
without_cancel
pub fn without_cancel(parent &Context) Context
Purpose
without_cancel is WithoutCancel: values are copied, deadline and cancellation are not. The new Done channel never closes.
Parameters
parent &Context- parent (borrowed; caller keeps it; type &Context)
Returns
Context — a value of this type