Skip to content

Commit cfcf8b4

Browse files
authored
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 9c47990 commit cfcf8b4

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
@@ -3,6 +3,15 @@ import Combine
33
import SwiftUI
44
import XCTestDynamicOverlay
55

6+
// NB: Deprecated after 0.36.0:
7+
8+
extension ViewStore {
9+
@available(*, deprecated, renamed: "yield(while:)")
10+
public func suspend(while predicate: @escaping (State) -> Bool) async {
11+
await self.yield(while: predicate)
12+
}
13+
}
14+
615
// NB: Deprecated after 0.34.0:
716

817
extension Effect {

Sources/ComposableArchitecture/ViewStore.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private struct HashableWrapper<Value>: Hashable {
440440
while predicate: @escaping (State) -> Bool
441441
) async {
442442
self.send(action)
443-
await self.suspend(while: predicate)
443+
await self.yield(while: predicate)
444444
}
445445

446446
/// Sends an action into the store and then suspends while a piece of state is `true`.
@@ -458,14 +458,17 @@ private struct HashableWrapper<Value>: Hashable {
458458
while predicate: @escaping (State) -> Bool
459459
) async {
460460
withAnimation(animation) { self.send(action) }
461-
await self.suspend(while: predicate)
461+
await self.yield(while: predicate)
462462
}
463463

464-
/// Suspends while a predicate on state is `true`.
464+
/// Suspends the current task while a predicate on state is `true`.
465+
///
466+
/// If you want to suspend at the same time you send an action to the view store, use
467+
/// ``send(_:while:)``.
465468
///
466469
/// - Parameter predicate: A predicate on `State` that determines for how long this method
467470
/// should suspend.
468-
public func suspend(while predicate: @escaping (State) -> Bool) async {
471+
public func yield(while predicate: @escaping (State) -> Bool) async {
469472
if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) {
470473
_ = await self.publisher
471474
.values

Tests/ComposableArchitectureTests/ViewStoreTests.swift

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

0 commit comments

Comments
 (0)