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 before doAsync2, which is performed before doAsync3.

    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)
  • log

    Declaration

    Swift

    public static var log: Logger { get }