contextx

package
v0.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package contextx 提供上下文(context.Context)变体工具。

当前能力:ValueOnlyFrom——剥离 Done/Err/Deadline 的只传值轻量 ctx。

典型场景:把请求携带的业务值(trace、用户标识等)传给后台任务, 但不继承请求的取消/超时——否则请求结束时后台任务被连带取消, 或 deadline 已近乎耗尽导致后台任务立刻失败。

bgCtx := contextx.ValueOnlyFrom(reqCtx)
async.GoSafe(func() { process(bgCtx, payload) })

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValueOnlyFrom

func ValueOnlyFrom(parent context.Context) context.Context

ValueOnlyFrom 返回只保留取值能力的 context.Context:Value 透传 parent, 剥离 Done/Err/Deadline——parent 的取消与超时不影响返回的 ctx。 适合把请求 ctx 携带的值交给后台任务(配合 async.GoSafe 等), 同时切断内部取消的传播。parent 须非 nil(与标准库行为一致)。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL