TaskQueue
public class TaskQueue<Success>
A helper for executing asynchronous work serially.
-
Declaration
Swift
public init()
-
sync(block:
Asynchronous) Serializes asynchronous requests made from an async context
Given an invocation like
let tq = TaskQueue<Int>() let v1 = try await tq.sync { try await doAsync1() } let v2 = try await tq.sync { try await doAsync2() } let v3 = try await tq.sync { try await doAsync3() }
TaskQueue serializes this work so that
doAsync1
is performed beforedoAsync2
, which is performed beforedoAsync3
.Declaration
Swift
public func sync(block: @escaping @Sendable () async throws -> Success) async throws -> Success
-
Declaration
Swift
public func async(block: @escaping @Sendable () async throws -> Success)
-
Declaration
Swift
public static var log: Logger { get }