Skip to content

Commit 0807f9a

Browse files
authored
Rename certain Effect APIs (#92)
* Rename certain Effect APIs * Move deprecations * Fix
1 parent 940207c commit 0807f9a

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-ResuableOfflineDownloads/DownloadClient.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension DownloadClient {
2424
}
2525
},
2626
download: { id, url in
27-
Effect.async { subscriber in
27+
.run { subscriber in
2828
let task = URLSession.shared.dataTask(with: url) { data, _, error in
2929
switch (data, error) {
3030
case let (.some(data), _):
@@ -54,7 +54,8 @@ extension DownloadClient {
5454
dependencies[id] = nil
5555
}
5656
}
57-
})
57+
}
58+
)
5859
}
5960

6061
private struct Dependencies {

Examples/MotionManager/MotionManager/MotionClient/Live.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CoreMotion
55
extension MotionClient {
66
static let live = MotionClient(
77
create: { id in
8-
Effect.async { subscriber in
8+
.run { subscriber in
99
let manager = MotionManager(
1010
manager: CMMotionManager(),
1111
handler: { motion, error in

Examples/SpeechRecognition/SpeechRecognition/SpeechClient/Live.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension SpeechClient {
1717
}
1818
},
1919
recognitionTask: { id, request in
20-
Effect.async { subscriber in
20+
Effect.run { subscriber in
2121
let cancellable = AnyCancellable {
2222
dependencies[id]?.cancel()
2323
dependencies[id] = nil

Sources/ComposableArchitecture/Effect.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public struct Effect<Output, Failure: Error>: Publisher {
140140
/// sending the current status immediately, and then if the current status is `notDetermined` it
141141
/// can request authorization, and once a status is received it can send that back to the effect:
142142
///
143-
/// Effect.async { subscriber in
143+
/// Effect.run { subscriber in
144144
/// subscriber.send(MPMediaLibrary.authorizationStatus())
145145
///
146146
/// guard MPMediaLibrary.authorizationStatus() == .notDetermined else {
@@ -161,7 +161,7 @@ public struct Effect<Output, Failure: Error>: Publisher {
161161
/// - Parameter work: A closure that accepts a `Subscriber` value and returns a cancellable. When
162162
/// the `Effect` is completed, the cancellable will be used to clean up any resources created
163163
/// when the effect was started.
164-
public static func async(
164+
public static func run(
165165
_ work: @escaping (Effect.Subscriber<Output, Failure>) -> Cancellable
166166
) -> Self {
167167
AnyPublisher.create(work).eraseToEffect()
@@ -243,7 +243,7 @@ extension Effect where Failure == Swift.Error {
243243
///
244244
/// For example, to load a user from some JSON on the disk, one can wrap that work in an effect:
245245
///
246-
/// Effect<User, Error>.sync {
246+
/// Effect<User, Error>.catching {
247247
/// let fileUrl = URL(
248248
/// fileURLWithPath: NSSearchPathForDirectoriesInDomains(
249249
/// .documentDirectory, .userDomainMask, true
@@ -257,7 +257,7 @@ extension Effect where Failure == Swift.Error {
257257
///
258258
/// - Parameter work: A closure encapsulating some work to execute in the real world.
259259
/// - Returns: An effect.
260-
public static func sync(_ work: @escaping () throws -> Output) -> Self {
260+
public static func catching(_ work: @escaping () throws -> Output) -> Self {
261261
.future { $0(Result { try work() }) }
262262
}
263263
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Combine
2+
3+
// NB: Deprecated after 0.1.3:
4+
5+
extension Effect {
6+
@available(*, deprecated, renamed: "run")
7+
public static func async(
8+
_ work: @escaping (Effect.Subscriber<Output, Failure>) -> Cancellable
9+
) -> Self {
10+
self.run(work)
11+
}
12+
}
13+
14+
extension Effect where Failure == Swift.Error {
15+
@available(*, deprecated, renamed: "catching")
16+
public static func sync(_ work: @escaping () throws -> Output) -> Self {
17+
self.catching(work)
18+
}
19+
}

Tests/ComposableArchitectureTests/EffectTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ final class EffectTests: XCTestCase {
9393
}
9494

9595
func testEffectSubscriberInitializer() {
96-
let effect = Effect<Int, Never>.async { subscriber in
96+
let effect = Effect<Int, Never>.run { subscriber in
9797
subscriber.send(1)
9898
subscriber.send(2)
9999
self.scheduler.schedule(after: self.scheduler.now.advanced(by: .seconds(1))) {
@@ -130,7 +130,7 @@ final class EffectTests: XCTestCase {
130130
func testEffectSubscriberInitializer_WithCancellation() {
131131
struct CancelId: Hashable {}
132132

133-
let effect = Effect<Int, Never>.async { subscriber in
133+
let effect = Effect<Int, Never>.run { subscriber in
134134
subscriber.send(1)
135135
self.scheduler.schedule(after: self.scheduler.now.advanced(by: .seconds(1))) {
136136
subscriber.send(2)

0 commit comments

Comments
 (0)