corectx

package
v0.4.27 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: LGPL-2.1 Imports: 4 Imported by: 3

Documentation

Overview

Package corectx 定义 service 与 runtime 共用的上下文契约。

Package corectx 抽象了框架中通用的上下文能力,包括:

  • 父 context、终止与完成信号;
  • panic 自动恢复与错误上报策略;
  • 等待组/屏障,用于协调 service 与 runtime 的关闭顺序;
  • 当前上下文和并发安全上下文提供器接口。

service.Context、runtime.Context,以及 entity/component 对当前上下文的暴露方式, 都依赖这些基础接口。

Terminate 只发出取消信号;Terminated 在宿主完成清理后才兑现。WaitGroup 是关闭屏障, 宿主开始退出后不再接受新任务,并等待已经加入的任务完成。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnsafeContext deprecated

func UnsafeContext(ctx Context) _UnsafeContext

UnsafeContext 暴露上下文初始化与完成信号等框架内部能力。

Deprecated: 仅供框架内部使用。

Types

type AsyncScopeProvider added in v0.4.27

type AsyncScopeProvider interface {
	AsyncScope() *async.Scope
}

AsyncScopeProvider 提供绑定对象生命周期的异步任务作用域。 返回的 Scope 可跨 goroutine 安全使用;具体关闭时机由实现对象的生命周期决定。

type ConcurrentContextProvider

type ConcurrentContextProvider interface {
	// ConcurrentContextCache 返回并发上下文的接口缓存。
	ConcurrentContextCache() iface.Cache
}

ConcurrentContextProvider 提供可跨协程使用的并发上下文。

type Context

type Context interface {
	context.Context
	AsyncScopeProvider

	// ParentContext 返回创建当前上下文时使用的父上下文。
	ParentContext() context.Context
	// AutoRecover 报告框架回调是否自动恢复 panic。
	AutoRecover() bool
	// ReportError 返回自动恢复 panic 后用于非阻塞上报错误的频道。
	ReportError() chan error
	// WaitGroup 返回用于协调关闭的任务屏障。
	WaitGroup() WaitGroup
	// Terminate 发出取消信号,并返回宿主完成清理时兑现的 Signal。
	Terminate() async.Signal
	// Terminated 返回宿主完成清理时兑现的 Signal。
	Terminated() async.Signal
	// contains filtered or unexported methods
}

Context 定义 Service 与 Runtime 共享的生命周期上下文能力。

type ContextBehavior

type ContextBehavior struct {
	context.Context
	// contains filtered or unexported fields
}

ContextBehavior 提供 Context 的通用实现,供 Service 与 Runtime 上下文嵌入。

func (*ContextBehavior) AsyncScope added in v0.4.27

func (ctx *ContextBehavior) AsyncScope() *async.Scope

AsyncScope 返回绑定宿主生命周期的后台任务作用域。

func (*ContextBehavior) AutoRecover

func (ctx *ContextBehavior) AutoRecover() bool

AutoRecover 报告框架回调是否自动恢复 panic。

func (*ContextBehavior) ParentContext

func (ctx *ContextBehavior) ParentContext() context.Context

ParentContext 返回创建当前上下文时使用的父上下文。

func (*ContextBehavior) ReportError

func (ctx *ContextBehavior) ReportError() chan error

ReportError 返回自动恢复 panic 后用于非阻塞上报错误的频道。

func (*ContextBehavior) Terminate

func (ctx *ContextBehavior) Terminate() async.Signal

Terminate 发出取消信号,并返回宿主完成清理时兑现的 Signal。

func (*ContextBehavior) Terminated

func (ctx *ContextBehavior) Terminated() async.Signal

Terminated 返回宿主完成清理时兑现的 Signal。

func (*ContextBehavior) WaitGroup

func (ctx *ContextBehavior) WaitGroup() WaitGroup

WaitGroup 返回用于协调关闭的任务屏障。

type CurrentContextProvider

type CurrentContextProvider interface {
	ConcurrentContextProvider
	// CurrentContextCache 返回当前上下文的接口缓存。
	CurrentContextCache() iface.Cache
}

CurrentContextProvider 提供只能在所属执行协程中使用的当前上下文。

type WaitGroup

type WaitGroup interface {
	// Join 调整任务计数;屏障已关闭时拒绝正增量并返回 false,delta 为 0 时 panic。
	Join(delta int64) bool
	// Done 将任务计数减一。
	Done()
	// Wait 阻塞到屏障关闭且全部已加入任务完成。
	Wait()
	// Closed 报告屏障是否已关闭并停止接收新任务。
	Closed() bool
	// Count 返回内部屏障计数;关闭前包含一个宿主持有的基准计数。
	Count() int64
}

WaitGroup 是用于协调宿主关闭的并发安全屏障。

Jump to

Keyboard shortcuts

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