代码拉取完成,页面将自动刷新
package routine
// ThreadLocal provides goroutine-local variables.
type ThreadLocal[T any] interface {
// Get returns the value in the current goroutine's local threadLocals or inheritableThreadLocals, if it was set before.
Get() T
// Set copy the value into the current goroutine's local threadLocals or inheritableThreadLocals.
Set(value T)
// Remove delete the value from the current goroutine's local threadLocals or inheritableThreadLocals.
Remove()
}
// Supplier provides a function that returns a value of type T.
type Supplier[T any] func() T
// NewThreadLocal create and return a new ThreadLocal instance.
// The initial value stored with the default value of type T.
func NewThreadLocal[T any]() ThreadLocal[T] {
return &threadLocal[T]{index: nextThreadLocalIndex()}
}
// NewThreadLocalWithInitial create and return a new ThreadLocal instance.
// The initial value stored as the return value of the method supplier.
func NewThreadLocalWithInitial[T any](supplier Supplier[T]) ThreadLocal[T] {
return &threadLocal[T]{index: nextThreadLocalIndex(), supplier: supplier}
}
// NewInheritableThreadLocal create and return a new ThreadLocal instance.
// The initial value stored with the default value of type T.
// The value can be inherited to sub goroutines witch started by Go, GoWait, GoWaitResult methods.
// The value can be captured to FutureTask which created by WrapTask, WrapWaitTask, WrapWaitResultTask methods.
func NewInheritableThreadLocal[T any]() ThreadLocal[T] {
return &inheritableThreadLocal[T]{index: nextInheritableThreadLocalIndex()}
}
// NewInheritableThreadLocalWithInitial create and return a new ThreadLocal instance.
// The initial value stored as the return value of the method supplier.
// The value can be inherited to sub goroutines witch started by Go, GoWait, GoWaitResult methods.
// The value can be captured to FutureTask which created by WrapTask, WrapWaitTask, WrapWaitResultTask methods.
func NewInheritableThreadLocalWithInitial[T any](supplier Supplier[T]) ThreadLocal[T] {
return &inheritableThreadLocal[T]{index: nextInheritableThreadLocalIndex(), supplier: supplier}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。