XU XUv0.8.8
EN

API

#context

import: #context

counts: 9 函数, 2 方法, 2 类型, 0 常量, 0 方法集

Background / WithCancel / WithTimeout;Done 为 chan。无 WithValue。

struct Context

XuAPI
pub struct Context {
    pub done chan int
    pub deadline_ns int
    pub keys []string
    pub vals []string
}

用途

`context` 最小面:Background / WithCancel / WithTimeout。 Done 是 chan;cancel 即 close。副本共享同一条 chan(与 sync.Mutex 相同)。 `with_cancel_parent` adds cancellation propagation without requiring a runtime interface value: a small watcher goroutine waits on the parent's done channel and closes the child exactly once.

参数

done chan int
字段(通道;类型 chan int)
deadline_ns int
字段(int)
keys []string
字段([]string)
vals []string
字段([]string)

struct Cancel

XuAPI
pub struct Cancel {
    pub ctx Context
}

用途

公开结构体 `Cancel`。

参数

ctx Context
字段(Context)

background

XuAPI
pub fn background() Context

用途

根上下文。

参数

无

返回

Context — 该类型的值

with_cancel

XuAPI
pub fn with_cancel() Cancel

用途

派生一个带 cancel 的新值。

参数

无

返回

Cancel — 该类型的值

(&mut Cancel) cancel

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

用途

`&mut Cancel` 上的方法:取消。

参数

c &mut Cancel
接收者 &mut Cancel(可变借用)

with_cancel_parent

XuAPI
pub fn with_cancel_parent(parent &Context) Cancel

用途

派生一个带 cancel parent 的新值。

参数

parent &Context
parent(借用,调用方仍持有;类型 &Context)

返回

Cancel — 该类型的值

with_timeout

XuAPI
pub fn with_timeout(timeout_ns int) Cancel

用途

派生一个带 timeout 的新值。

参数

timeout_ns int
超时(纳秒)(int)

返回

Cancel — 该类型的值

with_deadline

XuAPI
pub fn with_deadline(deadline_ns int) Cancel

用途

派生一个带 deadline 的新值。

参数

deadline_ns int
deadline_ns(int)

返回

Cancel — 该类型的值

(Context) deadline

XuAPI
pub fn (c Context) deadline() int

用途

`Context` 上的方法:截止时间。

参数

c Context
接收者 Context(值接收者)

返回

int — 该类型的值

err

XuAPI
pub fn err(c &Context) int

用途

err,返回 int。失败时 throw。

参数

c &Context
字节或字符码(借用,调用方仍持有;类型 &Context)

返回

int — 该类型的值

with_value

XuAPI
pub fn with_value(parent &Context, key string, val string) Context

用途

派生一个带 value 的新值。

参数

parent &Context
parent(借用,调用方仍持有;类型 &Context)
key string
键(string)
val string
值(string)

返回

Context — 该类型的值

value

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

用途

值。失败时 throw。

参数

c &Context
字节或字符码(借用,调用方仍持有;类型 &Context)
key string
键(string)

返回

string — 结果字符串

without_cancel

XuAPI
pub fn without_cancel(parent &Context) Context

用途

without取消。

参数

parent &Context
parent(借用,调用方仍持有;类型 &Context)

返回

Context — 该类型的值