Skip to content

Commit 904b193

Browse files
committed
RAS changes.
1 parent 47eaa7b commit 904b193

File tree

3 files changed

+32
-36
lines changed

3 files changed

+32
-36
lines changed

Examples/CaseStudies/SwiftUICaseStudies/FactClient.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ extension FactClient {
2626
return "\(number) is a good number Brent"
2727
}
2828
}
29-
.setFailureType(to: Error.self)
30-
.eraseToEffect()
29+
.promoteError(Error.self)
3130
}
3231
)
3332
#else

Sources/ComposableArchitecture/Beta/Concurrency.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import SwiftUI
3737
/// - Returns: An effect wrapping the given asynchronous work.
3838
public static func task(
3939
priority: TaskPriority? = nil,
40-
operation: @escaping @Sendable () async -> Output
41-
) -> Self where Failure == Never {
40+
operation: @escaping @Sendable () async -> Value
41+
) -> Self where Error == Never {
4242
var task: Task<Void, Never>?
4343
return .future { callback in
4444
task = Task(priority: priority) {
@@ -48,8 +48,7 @@ import SwiftUI
4848
callback(.success(output))
4949
}
5050
}
51-
.handleEvents(receiveCancel: { task?.cancel() })
52-
.eraseToEffect()
51+
.on(disposed: { task?.cancel() })
5352
}
5453

5554
/// Wraps an asynchronous unit of work in an effect.
@@ -82,26 +81,27 @@ import SwiftUI
8281
/// - Returns: An effect wrapping the given asynchronous work.
8382
public static func task(
8483
priority: TaskPriority? = nil,
85-
operation: @escaping @Sendable () async throws -> Output
86-
) -> Self where Failure == Error {
87-
Deferred<Publishers.HandleEvents<PassthroughSubject<Output, Failure>>> {
88-
let subject = PassthroughSubject<Output, Failure>()
84+
operation: @escaping @Sendable () async throws -> Value
85+
) -> Self where Error == Swift.Error {
86+
deferred {
87+
let subject = Signal<Value, Error>.pipe()
8988
let task = Task(priority: priority) {
9089
do {
9190
try Task.checkCancellation()
9291
let output = try await operation()
9392
try Task.checkCancellation()
94-
subject.send(output)
95-
subject.send(completion: .finished)
93+
subject.input.send(value: output)
94+
subject.input.sendCompleted()
9695
} catch is CancellationError {
97-
subject.send(completion: .finished)
96+
subject.input.sendCompleted()
9897
} catch {
99-
subject.send(completion: .failure(error))
98+
subject.input.send(error: error)
10099
}
101100
}
102-
return subject.handleEvents(receiveCancel: task.cancel)
101+
102+
return subject.output.producer
103+
.on(disposed: task.cancel)
103104
}
104-
.eraseToEffect()
105105
}
106106
}
107107

Tests/ComposableArchitectureTests/EffectTests.swift

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ final class EffectTests: XCTestCase {
179179
expectation.fulfill()
180180
return 42
181181
}
182-
.sink(receiveValue: { result = $0 })
183-
.store(in: &self.cancellables)
182+
.startWithValues { result = $0 }
184183
self.wait(for: [expectation], timeout: 0)
185184
XCTAssertEqual(result, 42)
186185
}
@@ -191,24 +190,23 @@ final class EffectTests: XCTestCase {
191190
let expectation = self.expectation(description: "Complete")
192191
struct MyError: Error {}
193192
var result: Error?
194-
Effect<Int, Error>.task {
193+
let disposable = Effect<Int, Error>.task {
195194
expectation.fulfill()
196195
throw MyError()
197196
}
198-
.sink(
199-
receiveCompletion: {
200-
switch $0 {
201-
case .finished:
202-
XCTFail()
203-
case let .failure(error):
204-
result = error
205-
}
197+
.on(
198+
failed: { error in
199+
result = error
206200
},
207-
receiveValue: { _ in XCTFail() }
208-
)
209-
.store(in: &self.cancellables)
201+
value: { _ in
202+
XCTFail()
203+
}
204+
).logEvents()
205+
.start()
206+
210207
self.wait(for: [expectation], timeout: 0)
211208
XCTAssertNotNil(result)
209+
disposable.dispose()
212210
}
213211

214212
func testCancellingTask() {
@@ -228,12 +226,11 @@ final class EffectTests: XCTestCase {
228226
let expectation = self.expectation(description: "Complete")
229227
Effect<Int, Error>.task {
230228
try await work()
231-
}
232-
.sink(
233-
receiveCompletion: { _ in expectation.fulfill() },
234-
receiveValue: { _ in XCTFail() }
235-
)
236-
.store(in: &self.cancellables)
229+
}.on(
230+
completed: { expectation.fulfill() },
231+
value: { _ in XCTFail() }
232+
).start()
233+
237234
self.wait(for: [expectation], timeout: 0.2)
238235
}
239236
#endif

0 commit comments

Comments
 (0)