Skip to content

Commit

Permalink
refactor isolated actor polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jun 24, 2024
1 parent 236c14b commit 6b87084
Showing 1 changed file with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ extension MultipartFramesToRawPartsSequence: AsyncSequence {
}
}

extension AsyncIteratorProtocol {
/// Asynchronously advances to the next element and returns it, or ends the
/// sequence if there is no next element.
///
/// - Returns: The next element, if it exists, or `nil` to signal the end of
/// the sequence.
fileprivate mutating func next(isolatedWith actor: isolated (any Actor)?) async throws -> Self.Element? {
if #available(macOS 15, iOS 18.0, tvOS 18.0, watchOS 11.0, macCatalyst 18.0, visionOS 2.0, *) {
#if compiler(>=6.0)
return try await self.next(isolation: actor)
#else
return try await self.next()
#endif
} else {
return try await self.next()
}
}
}

extension HTTPBody {

/// Creates a new body from the provided header fields and body closure.
Expand Down Expand Up @@ -342,17 +361,8 @@ extension MultipartFramesToRawPartsSequence {
switch stateMachine.nextFromPartSequence() {
case .returnNil: return nil
case .fetchFrame:
let frame: Upstream.AsyncIterator.Element?
var upstream = upstream
if #available(macOS 15, iOS 18.0, tvOS 18.0, watchOS 11.0, macCatalyst 18.0, visionOS 2.0, *) {
#if compiler(>=6.0)
frame = try await upstream.next(isolation: self)
#else
frame = try await upstream.next()
#endif
} else {
frame = try await upstream.next()
}
let frame = try await upstream.next(isolatedWith: self)
self.upstream = upstream
switch stateMachine.partReceivedFrame(frame) {
case .returnNil: return nil
Expand All @@ -374,17 +384,8 @@ extension MultipartFramesToRawPartsSequence {
switch stateMachine.nextFromBodySubsequence() {
case .returnNil: return nil
case .fetchFrame:
let frame: Upstream.AsyncIterator.Element?
var upstream = upstream
if #available(macOS 15, iOS 18.0, tvOS 18.0, watchOS 11.0, macCatalyst 18.0, visionOS 2.0, *) {
#if compiler(>=6.0)
frame = try await upstream.next(isolation: self)
#else
frame = try await upstream.next()
#endif
} else {
frame = try await upstream.next()
}
let frame = try await upstream.next(isolatedWith: self)
self.upstream = upstream
switch stateMachine.bodyReceivedFrame(frame) {
case .returnNil: return nil
Expand Down

0 comments on commit 6b87084

Please sign in to comment.