Skip to content

Commit c7d7d3c

Browse files
authored
Make sure debounced values are delivered on specified scheduler. (#714)
* Make sure debounced values are delivered on specified scheduler. * fix deferring too * wip
1 parent 67ccab6 commit c7d7d3c

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

Examples/Search/Search/SearchView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ let searchReducer = Reducer<SearchState, SearchAction, SearchEnvironment> {
6868

6969
return environment.weatherClient
7070
.searchLocation(query)
71-
.receive(on: environment.mainQueue)
7271
.catchToEffect()
7372
.debounce(id: SearchLocationId(), for: 0.3, scheduler: environment.mainQueue)
7473
.map(SearchAction.locationsResponse)

Sources/ComposableArchitecture/Effects/Debouncing.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ extension Effect {
1414
/// struct SearchId: Hashable {}
1515
///
1616
/// return environment.search(text)
17-
/// .map(Action.searchResponse)
1817
/// .debounce(id: SearchId(), for: 0.5, scheduler: environment.mainQueue)
18+
/// .map(Action.searchResponse)
1919
/// ```
2020
///
2121
/// - Parameters:
@@ -33,7 +33,7 @@ extension Effect {
3333
Just(())
3434
.setFailureType(to: Failure.self)
3535
.delay(for: dueTime, scheduler: scheduler, options: options)
36-
.flatMap { self }
36+
.flatMap { self.receive(on: scheduler) }
3737
.eraseToEffect()
3838
.cancellable(id: id, cancelInFlight: true)
3939
}

Sources/ComposableArchitecture/Effects/Deferring.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ extension Effect {
66
/// ```swift
77
/// case let .textChanged(text):
88
/// return environment.search(text)
9-
/// .map(Action.searchResponse)
109
/// .deferred(for: 0.5, scheduler: environment.mainQueue)
10+
/// .map(Action.searchResponse)
1111
/// ```
1212
///
1313
/// - Parameters:
@@ -24,7 +24,7 @@ extension Effect {
2424
Just(())
2525
.setFailureType(to: Failure.self)
2626
.delay(for: dueTime, scheduler: scheduler, options: options)
27-
.flatMap { self }
27+
.flatMap { self.receive(on: scheduler) }
2828
.eraseToEffect()
2929
}
3030
}

0 commit comments

Comments
 (0)