Skip to content

Commit 625a3e0

Browse files
committed
Rename ViewStore.suspend(while:) to yield(while:) (#1151)
The naming of `ViewStore.suspend(while:)` was inspired by `Task.suspend()`, which was deprecated and renamed to `Task.yield()` long ago. Let's do the same here and call it `ViewStore.yield(while:)`.
1 parent 7713fbe commit 625a3e0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Sources/ComposableArchitecture/Internal/Deprecations.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ import SwiftUI
99
import os
1010
#endif
1111

12+
// NB: Deprecated after 0.36.0:
13+
14+
extension ViewStore {
15+
@available(*, deprecated, renamed: "yield(while:)")
16+
public func suspend(while predicate: @escaping (State) -> Bool) async {
17+
await self.yield(while: predicate)
18+
}
19+
}
20+
1221
// NB: Deprecated after 0.34.0:
1322

1423
extension Effect {

Sources/ComposableArchitecture/ViewStore.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ private struct HashableWrapper<Value>: Hashable {
453453
while predicate: @escaping (State) -> Bool
454454
) async {
455455
self.send(action)
456-
await self.suspend(while: predicate)
456+
await self.yield(while: predicate)
457457
}
458458

459459
#if canImport(SwiftUI)
@@ -472,15 +472,18 @@ private struct HashableWrapper<Value>: Hashable {
472472
while predicate: @escaping (State) -> Bool
473473
) async {
474474
withAnimation(animation) { self.send(action) }
475-
await self.suspend(while: predicate)
475+
await self.yield(while: predicate)
476476
}
477477
#endif
478478

479-
/// Suspends while a predicate on state is `true`.
479+
/// Suspends the current task while a predicate on state is `true`.
480+
///
481+
/// If you want to suspend at the same time you send an action to the view store, use
482+
/// ``send(_:while:)``.
480483
///
481484
/// - Parameter predicate: A predicate on `State` that determines for how long this method
482485
/// should suspend.
483-
public func suspend(while predicate: @escaping (State) -> Bool) async {
486+
public func yield(while predicate: @escaping (State) -> Bool) async {
484487
let cancellable = Box<Disposable?>(wrappedValue: nil)
485488
try? await withTaskCancellationHandler(
486489
handler: { cancellable.wrappedValue?.dispose() },

Tests/ComposableArchitectureTests/ViewStoreTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ final class ViewStoreTests: XCTestCase {
227227
XCTAssertNoDifference(viewStore.state, false)
228228
viewStore.send(.tapped)
229229
XCTAssertNoDifference(viewStore.state, true)
230-
await viewStore.suspend(while: { $0 })
230+
await viewStore.yield(while: { $0 })
231231
XCTAssertNoDifference(viewStore.state, false)
232232
expectation.fulfill()
233233
}

0 commit comments

Comments
 (0)