static var current: ServiceContext?
A ServiceContext
is automatically propagated through task-local storage. This API enables binding a top-level ServiceContext
and implicitly passes it to child tasks when using structured concurrency.
static var topLevel: ServiceContext
Creates a new empty “top level” context, generally used as an “initial” context to immediately be populated with some values by a framework or runtime. Another use case is for tasks starting in the “background” (e.g. on a timer), which don’t have a “request context” per se that they can pick up, and as such they have to create a “top level” context for their work.
static func TODO(StaticString?, function: String, file: String, line: UInt) -> ServiceContext
A context intended as a placeholder until a real value can be passed through a function call.
static func withValue<T>(ServiceContext?, isolation: isolated (any Actor)?, operation: () async throws -> T) async rethrows -> T
Convenience API to bind the task-local current
to the passed value
, and execute the passed operation
.