Closed
Description
A common pattern with services is
try await withTaskCancellationHandler {
try await withGracefulShutdownHandler {
doStuff()
} onGracefulShutdown {
stop()
}
} onCancel: {
stop()
}
Is it worthwhile providing a small helper API to do this eg
@_unsafeInheritExecutor
public func withCancellationOrGracefulShutdownHandler<T>(
operation: () async throws -> T,
onCancellationOrGracefulShutdown handler: @Sendable @escaping () -> Void
) async rethrows -> T {
return try await withTaskCancellationHandler {
try await withGracefulShutdownHandler(operation: operation, onGracefulShutdown: handler)
} onCancel: {
handler()
}
}
Metadata
Metadata
Assignees
Labels
No labels