Skip to content

Commit

Permalink
Make ErrorSequence always available
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jun 24, 2023
1 parent bd96d19 commit 8d6f936
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Sources/Queue/AsyncQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ extension Task: Awaitable {
}

public final class AsyncQueue: @unchecked Sendable {
#if compiler(>=5.9)
public typealias ErrorSequence = AsyncStream<Error>
#endif

public struct Attributes: OptionSet, Sendable {
public let rawValue: UInt64
Expand Down Expand Up @@ -41,21 +39,25 @@ public final class AsyncQueue: @unchecked Sendable {
private let lock = NSLock()
private var pendingTasks = [UUID: QueueEntry]()
private let attributes: Attributes
#if compiler(>=5.9)
private let errorContinuation: ErrorSequence.Continuation

/// An AsyncSequence of all errors thrown from operations.
///
/// Errors are published here even if a reference to the operation task is held and awaited. But, it can still very useful for logging and debugging purposes. This sequence will not include any `CancellationError`s thrown.
public let errorSequence: ErrorSequence
#endif

public init(attributes: Attributes = []) {
self.attributes = attributes
self.lock.name = "AsyncQueue"

#if compiler(>=5.9)
(self.errorSequence, self.errorContinuation) = ErrorSequence.makeStream()
#else
var escapedContinuation: ErrorSequence.Continuation?

self.errorSequence = ErrorSequence { escapedContinuation = $0 }

self.errorContinuation = escapedContinuation!
#endif
}

Expand Down
2 changes: 0 additions & 2 deletions Tests/QueueTests/AsyncQueueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ final class AsyncQueueTests: XCTestCase {
}
}

#if compiler(>=5.9)
extension AsyncQueueTests {
func testPublishUncaughtErrors() async throws {
let queue = AsyncQueue(attributes: [.publishErrors])
Expand Down Expand Up @@ -273,4 +272,3 @@ extension AsyncQueueTests {

}
}
#endif

0 comments on commit 8d6f936

Please sign in to comment.