Skip to content

Commit 8f27c58

Browse files
stephencelismluisbrown
authored andcommitted
Force Effect.{debounce,deferred} through publisher (#1326)
* Force `Effect.{debounce,deferred}` through publisher Because publishers can be animated, we should force these helpers through our publisher endpoints, otherwise our next release could break animated schedulers. * wip Co-authored-by: Brandon Williams <[email protected]> (cherry picked from commit 41b39f117103d79f4848b62ceb8999df7d4fe283) # Conflicts: # Sources/ComposableArchitecture/Effects/Debouncing.swift # Sources/ComposableArchitecture/Effects/Deferring.swift # Sources/ComposableArchitecture/Effects/Timer.swift
1 parent 0a00e73 commit 8f27c58

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

Sources/ComposableArchitecture/Effects/Debouncing.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ extension Effect {
3232
switch self.operation {
3333
case .none:
3434
return .none
35-
case let .producer(producer):
35+
case .producer:
3636
return Self(
3737
operation: .producer(
3838
SignalProducer<Void, Never>.init(value: ())
3939
.promoteError(Failure.self)
4040
.delay(dueTime, on: scheduler)
41-
.flatMap(.latest) { producer.observe(on: scheduler) }
41+
.flatMap(.latest) { self.producer.observe(on: scheduler) }
4242
)
4343
)
4444
.cancellable(id: id, cancelInFlight: true)
@@ -48,7 +48,13 @@ extension Effect {
4848
await withTaskCancellation(id: id, cancelInFlight: true) {
4949
do {
5050
try await scheduler.sleep(for: .nanoseconds(Int(dueTime * TimeInterval(NSEC_PER_SEC))))
51-
await operation(send)
51+
await operation(
52+
Send { output in
53+
scheduler.schedule {
54+
send(output)
55+
}
56+
}
57+
)
5258
} catch {}
5359
}
5460
}

Sources/ComposableArchitecture/Effects/Deferring.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,39 @@ extension Effect {
1616
/// - scheduler: The scheduler you want to deliver the defer output to.
1717
/// - options: Scheduler options that customize the effect's delivery of elements.
1818
/// - Returns: An effect that will be executed after `dueTime`
19+
@available(iOS, deprecated: 9999.0, message: "Use 'scheduler.sleep' in 'Effect.run', instead.")
20+
@available(macOS, deprecated: 9999.0, message: "Use 'scheduler.sleep' in 'Effect.run', instead.")
21+
@available(tvOS, deprecated: 9999.0, message: "Use 'scheduler.sleep' in 'Effect.run', instead.")
22+
@available(
23+
watchOS, deprecated: 9999.0, message: "Use 'scheduler.sleep' in 'Effect.run', instead."
24+
)
1925
public func deferred(
2026
for dueTime: TimeInterval,
2127
scheduler: DateScheduler
2228
) -> Self {
2329
switch self.operation {
2430
case .none:
2531
return .none
26-
case let .producer(producer):
32+
case .producer:
2733
return Self(
2834
operation: .producer(
2935
SignalProducer<Void, Never>(value: ())
3036
.delay(dueTime, on: scheduler)
31-
.flatMap(.latest) { producer.observe(on: scheduler) }
37+
.flatMap(.latest) { self.producer.observe(on: scheduler) }
3238
)
3339
)
3440
case let .run(priority, operation):
3541
return Self(
3642
operation: .run(priority) { send in
3743
do {
3844
try await scheduler.sleep(for: .nanoseconds(Int(dueTime * TimeInterval(NSEC_PER_SEC))))
39-
await operation(send)
45+
await operation(
46+
Send { output in
47+
scheduler.schedule {
48+
send(output)
49+
}
50+
}
51+
)
4052
} catch {}
4153
}
4254
)

Sources/ComposableArchitecture/Effects/Timer.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ extension Effect where Output == Date, Failure == Never {
111111
/// - tolerance: The allowed timing variance when emitting events. Defaults to `nil`, which
112112
/// allows any variance.
113113
/// - options: Scheduler options passed to the timer. Defaults to `nil`.
114+
@available(iOS, deprecated: 9999.0, message: "Use 'scheduler.timer' in 'Effect.run', instead.")
115+
@available(macOS, deprecated: 9999.0, message: "Use 'scheduler.timer' in 'Effect.run', instead.")
116+
@available(tvOS, deprecated: 9999.0, message: "Use 'scheduler.timer' in 'Effect.run', instead.")
117+
@available(
118+
watchOS, deprecated: 9999.0, message: "Use 'scheduler.timer' in 'Effect.run', instead."
119+
)
114120
public static func timer(
115121
id: Any.Type,
116122
every interval: DispatchTimeInterval,

0 commit comments

Comments
 (0)