contextutil

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package contextutil provides context helpers. Package contextutil 提供 context 辅助函数。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Require

func Require(ctx context.Context) context.Context

Require returns ctx or panics on nil. Require 返回 ctx;ctx 为 nil 时 panic。

func WithTimeout

func WithTimeout[T any](parent context.Context, d time.Duration, fn func(context.Context) (T, error)) (T, error)

WithTimeout calls fn synchronously with context.WithTimeout(parent, d) and cancels the context when fn finishes. Timeout handling depends on fn observing the context. WithTimeout 使用 context.WithTimeout(parent, d) 同步调用 fn,并在 fn 结束时取消 context。 超时处理依赖 fn 响应 context。

Types

This section is empty.

Jump to

Keyboard shortcuts

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