XU XUv0.8.8
中文

API

#context

import: #context

counts: 9 fns, 2 methods, 2 types, 0 consts, 0 ifaces

Background / WithCancel / WithTimeout; Done is a chan. No WithValue.

struct Context

XuAPI
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)

struct Cancel

XuAPI
pub struct Cancel {
    pub ctx Context
}

Purpose

Public struct `Cancel`.

Parameters

ctx Context
field (Context)

background

XuAPI
pub fn background() Context

Purpose

background; returns Context.

Parameters

none

Returns

Context — a value of this type

with_cancel

XuAPI
pub fn with_cancel() Cancel

Purpose

Derive a new value with cancel.

Parameters

none

Returns

Cancel — a value of this type

(&mut Cancel) cancel

XuAPI
pub fn (c &mut Cancel) cancel()

Purpose

Call `cancel` on `&mut Cancel`.

Parameters

c &mut Cancel
receiver &mut Cancel (exclusive borrow)

with_cancel_parent

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

value

XuAPI
pub fn value(c &Context, key string) string

Purpose

value; returns string. Throws on failure.

Parameters

c &Context
byte or character code (borrowed; caller keeps it; type &Context)
key string
key (string)

Returns

string — result string

without_cancel

XuAPI
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