Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Join ¶
Join will associate two or more context.Context together, such that cancellation, deadlines, and errors are reported together.
If both input context.Context have a Deadline, then the one closest to the current time will be reported.
When checking if the joined context.Context has been cancelled, if either is done at the time of check, then the joined context is cancelled. If neither has been cancelled, then a goroutine is created to monitor when either context.Context is cancelled, cancelling the joint context.
Values are a bit more ambiguous. If multiple context.Context have a value for the same key, then there's no way for Join to pick the more correct value to return. In this case the first non-nil value is returned, and it might not be obvious to the caller which value that is. If you'd prefer to specify which value should be returned given multiple values, use JoinWithValuer.
If any context.Context is nil, then Join will panic.
func JoinWithValuer ¶
func JoinWithValuer(valuer JoinValuer, a, b context.Context, others ...context.Context) context.Context
JoinWithValuer is the same as Join, but allows the caller to specify a JoinValuer to inject logic for picking the more correct context value in ambiguous cases.
If any context.Context is nil, then JoinWithValuer will panic.
Types ¶
type JoinValuer ¶
type JoinValuer interface {
PickValue(a, b any) any // PickValue will be called to determine which value should be returned from a joint context if multiple underlying [context.Context] have a value for the same key.
}
JoinValuer allows the caller to solve for ambiguity while picking a value in multiple context.Context with the same key.
type JoinValuerFunc ¶
func (JoinValuerFunc) PickValue ¶
func (f JoinValuerFunc) PickValue(a, b any) any