Skip to content

Commit be7229f

Browse files
committed
Cleanup
1 parent dd1fe6f commit be7229f

File tree

7 files changed

+47
-53
lines changed

7 files changed

+47
-53
lines changed

Sources/ComposableArchitecture/Core.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ final class RootCore<Root: Reducer>: Core {
136136
task.cancel()
137137
}
138138
}
139-
case let .run(priority, name, operation):
139+
case let .run(name, priority, operation):
140140
withEscapedDependencies { continuation in
141141
let task = Task(name: name, priority: priority) { @MainActor [weak self] in
142142
let isCompleted = LockIsolated(false)

Sources/ComposableArchitecture/Effect.swift

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public struct Effect<Action>: Sendable {
88
case none
99
case publisher(AnyPublisher<Action, Never>)
1010
case run(
11-
TaskPriority? = nil,
12-
_ name: String? = nil,
13-
@Sendable (_ send: Send<Action>) async -> Void
11+
name: String? = nil,
12+
priority: TaskPriority? = nil,
13+
operation: @Sendable (_ send: Send<Action>) async -> Void
1414
)
1515
}
1616

@@ -101,7 +101,7 @@ extension Effect {
101101
) -> Self {
102102
withEscapedDependencies { escaped in
103103
Self(
104-
operation: .run(priority, name) { send in
104+
operation: .run(name: name, priority: priority) { send in
105105
await escaped.yield {
106106
do {
107107
try await operation(send)
@@ -274,7 +274,10 @@ extension Effect {
274274
.eraseToAnyPublisher()
275275
)
276276
)
277-
case let (.run(lhsPriority, lhsName, lhsOperation), .run(rhsPriority, rhsName, rhsOperation)):
277+
case (
278+
.run(let lhsName, let lhsPriority, let lhsOperation),
279+
.run(let rhsName, let rhsPriority, let rhsOperation)
280+
):
278281
return Self(
279282
operation: .run { send in
280283
await withTaskGroup(of: Void.self) { group in
@@ -334,16 +337,21 @@ extension Effect {
334337
.eraseToAnyPublisher()
335338
)
336339
)
337-
case let (.run(lhsPriority, lhsName, lhsOperation), .run(rhsPriority, rhsName, rhsOperation)):
340+
case (
341+
.run(let lhsName, let lhsPriority, let lhsOperation),
342+
.run(let rhsName, let rhsPriority, let rhsOperation)
343+
):
338344
return Self(
339345
operation: .run { send in
340346
if let lhsPriority {
341-
await Task(name: lhsName, priority: lhsPriority) { await lhsOperation(send) }.cancellableValue
347+
await Task(name: lhsName, priority: lhsPriority) { await lhsOperation(send) }
348+
.cancellableValue
342349
} else {
343350
await lhsOperation(send)
344351
}
345352
if let rhsPriority {
346-
await Task(name: rhsName, priority: rhsPriority) { await rhsOperation(send) }.cancellableValue
353+
await Task(name: rhsName, priority: rhsPriority) { await rhsOperation(send) }
354+
.cancellableValue
347355
} else {
348356
await rhsOperation(send)
349357
}
@@ -362,7 +370,7 @@ extension Effect {
362370
switch self.operation {
363371
case .none:
364372
return .none
365-
case let .publisher(publisher):
373+
case .publisher(let publisher):
366374
return .init(
367375
operation: .publisher(
368376
publisher
@@ -378,10 +386,10 @@ extension Effect {
378386
.eraseToAnyPublisher()
379387
)
380388
)
381-
case let .run(priority, name, operation):
389+
case .run(let name, let priority, let operation):
382390
return withEscapedDependencies { escaped in
383391
.init(
384-
operation: .run(priority, name) { send in
392+
operation: .run(name: name, priority: priority) { send in
385393
await escaped.yield {
386394
await operation(
387395
Send { action in
@@ -396,39 +404,25 @@ extension Effect {
396404
}
397405
}
398406

399-
#if !swift(>=6.2)
400-
public extension Task {
401-
/// Backwards compatibility shim for named Task initializers introduced in Swift 6.2
402-
///
403-
/// This extension provides the `name` parameter for Task initializers on Swift versions
404-
/// prior to 6.2.
405-
///
406-
/// - Important: On Swift < 6.2, the `name` parameter is accepted but ignored.
407-
/// No naming functionality is provided - this is purely for API compatibility.
408-
///
409-
/// Example usage:
410-
/// ```swift
411-
/// let task = Task(name: "DataLoader") {
412-
/// await loadUserData()
413-
/// }
414-
/// ```
415-
@discardableResult
416-
init(
417-
name: String,
418-
priority: TaskPriority? = nil,
419-
operation: @escaping @Sendable () async -> Success
420-
) where Failure == Never {
421-
self.init(priority: priority, operation: operation)
422-
}
407+
#if swift(<6.2)
408+
// NB: Backwards-compatible shims.
409+
extension Task {
410+
@discardableResult
411+
init(
412+
name: String,
413+
priority: TaskPriority? = nil,
414+
operation: @escaping @Sendable () async -> Success
415+
) where Failure == Never {
416+
self.init(priority: priority, operation: operation)
417+
}
423418

424-
/// Backwards compatibility shim for named throwing Task initializers
425-
@discardableResult
426-
init(
427-
name: String,
428-
priority: TaskPriority? = nil,
429-
operation: @escaping @Sendable () async throws -> Success
430-
) where Failure == Error {
431-
self.init(priority: priority, operation: operation)
419+
@discardableResult
420+
init(
421+
name: String,
422+
priority: TaskPriority? = nil,
423+
operation: @escaping @Sendable () async throws -> Success
424+
) where Failure == Error {
425+
self.init(priority: priority, operation: operation)
426+
}
432427
}
433-
}
434428
#endif

Sources/ComposableArchitecture/Effects/Animation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ extension Effect {
4242
TransactionPublisher(upstream: publisher, transaction: transaction).eraseToAnyPublisher()
4343
)
4444
)
45-
case let .run(priority, _, operation):
45+
case let .run(name, priority, operation):
4646
let uncheckedTransaction = UncheckedSendable(transaction)
4747
return Self(
48-
operation: .run(priority) { send in
48+
operation: .run(name: name, priority: priority) { send in
4949
await operation(
5050
Send { value in
5151
withTransaction(uncheckedTransaction.value) {

Sources/ComposableArchitecture/Effects/Cancellation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ extension Effect {
8383
.eraseToAnyPublisher()
8484
)
8585
)
86-
case let .run(priority, name, operation):
86+
case let .run(name, priority, operation):
8787
return withEscapedDependencies { continuation in
8888
return Self(
89-
operation: .run(priority, name) { send in
89+
operation: .run(name: name, priority: priority) { send in
9090
await continuation.yield {
9191
await withTaskCancellation(id: id, cancelInFlight: cancelInFlight) {
9292
await operation(send)

Sources/ComposableArchitecture/Effects/Publisher.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct _EffectPublisher<Action>: Publisher {
3030
return Empty().eraseToAnyPublisher()
3131
case let .publisher(publisher):
3232
return publisher
33-
case let .run(priority, name, operation):
33+
case let .run(name, priority, operation):
3434
return .create { subscriber in
3535
let task = Task(name: name, priority: priority) { @MainActor in
3636
defer { subscriber.send(completion: .finished) }

Sources/ComposableArchitecture/Internal/EffectActions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension Effect where Action: Sendable {
1515
cancellable.cancel()
1616
}
1717
}
18-
case let .run(priority, name, operation):
18+
case let .run(name, priority, operation):
1919
return AsyncStream { continuation in
2020
let task = Task(name: name, priority: priority) {
2121
await operation(Send { action in continuation.yield(action) })

Sources/ComposableArchitecture/Reducer/Reducers/SignpostReducer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ extension Effect {
114114
.eraseToAnyPublisher()
115115
)
116116
)
117-
case let .run(priority, name, operation):
117+
case let .run(name, priority, operation):
118118
return .init(
119-
operation: .run(priority, name) { send in
119+
operation: .run(name: name, priority: priority) { send in
120120
os_signpost(
121121
.begin, log: log, name: "Effect", signpostID: sid, "%sStarted from %s", prefix,
122122
actionOutput

0 commit comments

Comments
 (0)