Instance Method
task(priority:_:)
Spawns a Task whose lifetime is bound to the active scope.
@discardableResult func task(priority: TaskPriority? = nil, _ work: @escaping @Sendable () async -> Void) -> Task<Void, Never>
Parameters
- priority
An optional TaskPriority for the spawned task.
- work
The async work to run. Captured self references should be weak or explicit — the closure is @Sendable.
Return Value
The created Task. The result is discardable; callers typically rely on the lifecycle to cancel it.
Mentioned In
Discussion
The task is registered with the underlying lifecycle and is cancelled automatically by deactivate(). This replaces the role of disposeOnDeactivate from upstream RIBs.
func didBecomeActive() async {
task {
for await event in eventStream {
await self.handle(event)
}
}
}