Skip to content

Commit 38e635e

Browse files
fix: indentation issues
1 parent 1626281 commit 38e635e

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

Sources/AsyncAlgorithms/AsyncShareSequence.swift

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -590,44 +590,44 @@ where Base.Element: Sendable, Base: _SendableMetatype, Base.AsyncIterator: _Send
590590
}
591591

592592
func next(isolation actor: isolated (any Actor)?, id: Int) async throws -> Base.Element? {
593-
let iteratingTask = state.withLock { state -> IteratingTask in
594-
defer {
595-
if case .pending = state.iteratingTask {
596-
state.iteratingTask = .starting
597-
}
593+
let iteratingTask = state.withLock { state -> IteratingTask in
594+
defer {
595+
if case .pending = state.iteratingTask {
596+
state.iteratingTask = .starting
598597
}
599-
return state.iteratingTask
600598
}
601-
602-
if case .cancelled = iteratingTask { return nil }
603-
604-
if case .pending(let factory) = iteratingTask {
605-
let task: Task<Void, Never>
606-
// for the fancy dance of availability and canImport see the comment on the next check for details
607-
#if swift(>=6.2)
608-
if #available(macOS 26.0, iOS 26.0, tvOS 26.0, visionOS 26.0, *) {
609-
task = Task(name: "Share Iteration") { [factory, self] in
610-
await iterationLoop(factory: factory)
611-
}
612-
} else {
613-
task = Task.detached(name: "Share Iteration") { [factory, self] in
614-
await iterationLoop(factory: factory)
615-
}
616-
}
617-
#else
618-
task = Task.detached { [factory, self] in
619-
await iterationLoop(factory: factory)
620-
}
621-
#endif
622-
// Known Issue: there is a very small race where the task may not get a priority escalation during startup
623-
// this unfortuantely cannot be avoided since the task should ideally not be formed within the critical
624-
// region of the state. Since that could lead to potential deadlocks in low-core-count systems.
625-
// That window is relatively small and can be revisited if a suitable proof of safe behavior can be
626-
// determined.
627-
state.withLock { state in
628-
precondition(state.iteratingTask.isStarting)
629-
state.iteratingTask = .running(task)
630-
}
599+
return state.iteratingTask
600+
}
601+
602+
if case .cancelled = iteratingTask { return nil }
603+
604+
if case .pending(let factory) = iteratingTask {
605+
let task: Task<Void, Never>
606+
// for the fancy dance of availability and canImport see the comment on the next check for details
607+
#if swift(>=6.2)
608+
if #available(macOS 26.0, iOS 26.0, tvOS 26.0, visionOS 26.0, *) {
609+
task = Task(name: "Share Iteration") { [factory, self] in
610+
await iterationLoop(factory: factory)
611+
}
612+
} else {
613+
task = Task.detached(name: "Share Iteration") { [factory, self] in
614+
await iterationLoop(factory: factory)
615+
}
616+
}
617+
#else
618+
task = Task.detached { [factory, self] in
619+
await iterationLoop(factory: factory)
620+
}
621+
#endif
622+
// Known Issue: there is a very small race where the task may not get a priority escalation during startup
623+
// this unfortuantely cannot be avoided since the task should ideally not be formed within the critical
624+
// region of the state. Since that could lead to potential deadlocks in low-core-count systems.
625+
// That window is relatively small and can be revisited if a suitable proof of safe behavior can be
626+
// determined.
627+
state.withLock { state in
628+
precondition(state.iteratingTask.isStarting)
629+
state.iteratingTask = .running(task)
630+
}
631631
}
632632

633633
// withTaskPriorityEscalationHandler is only available for the '26 releases and the 6.2 version of
@@ -656,7 +656,6 @@ where Base.Element: Sendable, Base: _SendableMetatype, Base.AsyncIterator: _Send
656656
#else
657657
return try await nextIteration(id).get()
658658
#endif
659-
660659
}
661660
}
662661

Tests/AsyncAlgorithmsTests/TestShare.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ final class TestShare: XCTestCase {
9898
results1.withLock { $0.append(value) }
9999
}
100100
// Delay to allow consumer 2 to get ahead
101-
try? await Task.sleep(nanoseconds: 10_000_000)
101+
try? await Task.sleep(nanoseconds: 10_000_000)
102102
// Continue reading
103103
while let value = try await iterator.next(isolation: nil) {
104104
results1.withLock { $0.append(value) }

0 commit comments

Comments
 (0)