Skip to content

Commit 207fdfe

Browse files
authored
Remove schedulers in favor of using combine-schedulers (#184)
* Start using combine-schedulers. * fixes * wip
1 parent 5d741bf commit 207fdfe

File tree

9 files changed

+19
-422
lines changed

9 files changed

+19
-422
lines changed

Examples/MotionManager/MotionManager/MotionManagerView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ struct AppView_Previews: PreviewProvider {
146146
userAcceleration: .init(x: -cos(-3 * t), y: sin(2 * t), z: -cos(t))
147147
)
148148
)
149-
}
150-
.eraseToEffect()
151-
},
149+
}
150+
.setFailureType(to: MotionClient.Error.self)
151+
.eraseToEffect()
152+
},
152153
startDeviceMotionUpdates: { _ in .fireAndForget { isStarted = true } },
153154
stopDeviceMotionUpdates: { _ in .fireAndForget { isStarted = false } }
154155
)

Package.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ let package = Package(
2121
),
2222
],
2323
dependencies: [
24-
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.1.1")
24+
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "0.1.0"),
25+
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.1.1"),
2526
],
2627
targets: [
2728
.target(
2829
name: "ComposableArchitecture",
2930
dependencies: [
30-
"CasePaths"
31+
"CasePaths",
32+
"CombineSchedulers",
3133
]
3234
),
3335
.testTarget(
3436
name: "ComposableArchitectureTests",
3537
dependencies: [
38+
"CombineSchedulers",
3639
"ComposableArchitecture",
3740
]
3841
),

Sources/ComposableArchitecture/Effects/Timer.swift

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Combine
2-
import Foundation
2+
import CombineSchedulers
33

4-
extension Effect {
4+
extension Effect where Failure == Never {
55
/// Returns an effect that repeatedly emits the current time of the given
66
/// scheduler on the given interval.
77
///
@@ -35,24 +35,10 @@ extension Effect {
3535
options: S.SchedulerOptions? = nil
3636
) -> Effect where S: Scheduler, S.SchedulerTimeType == Output {
3737

38-
Deferred { () -> Publishers.HandleEvents<PassthroughSubject<Output, Failure>> in
39-
let subject = PassthroughSubject<S.SchedulerTimeType, Failure>()
40-
41-
let cancellable = scheduler.schedule(
42-
after: scheduler.now.advanced(by: interval),
43-
interval: interval,
44-
tolerance: tolerance ?? .seconds(.max),
45-
options: options
46-
) {
47-
subject.send(scheduler.now)
48-
}
49-
50-
return subject.handleEvents(
51-
receiveCompletion: { _ in cancellable.cancel() },
52-
receiveCancel: cancellable.cancel
53-
)
54-
}
55-
.eraseToEffect()
56-
.cancellable(id: id)
38+
Publishers.Timer(every: interval, tolerance: tolerance, scheduler: scheduler, options: options)
39+
.autoconnect()
40+
.setFailureType(to: Failure.self)
41+
.eraseToEffect()
42+
.cancellable(id: id)
5743
}
5844
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
@_exported import CasePaths
2+
@_exported import CombineSchedulers

Sources/ComposableArchitecture/Scheduling/AnyScheduler.swift

Lines changed: 0 additions & 99 deletions
This file was deleted.

Sources/ComposableArchitecture/Scheduling/TestScheduler.swift

Lines changed: 0 additions & 135 deletions
This file was deleted.

Tests/ComposableArchitectureTests/ComposableArchitectureTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Combine
2+
import CombineSchedulers
23
import ComposableArchitecture
34
import XCTest
45

Tests/ComposableArchitectureTests/ReducerTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Combine
2+
import CombineSchedulers
23
import ComposableArchitecture
34
import XCTest
45
import os.signpost

0 commit comments

Comments
 (0)