Commit 65f1fa0
authored
Fix
* Fix `Effect.throttle` data races and scheduler value return
The `Effect.throttle` operator had multiple data races when updating
`throttleTimes` and `throttleValues` shared state, because:
1. `Effect.throttle` can be called from any scheduler.
2. The internal `flatMap` runs on the current chain scheduler, but the
throttled (delayed) value runs on the passed in `scheduler` parameter
(which can be different).
By protecting shared state with a lock (similar to the cancellables'),
these data races should be addressed.
Additionally, the `Effect.throttle` should return all values in the
`scheduler` passed in, so that the API contract is honored and values
come from where callers expect them to.
## Changes
- Add new `throttleLock` `recursive lock to protect `throttleTimes`
and `throttleValues` shared state in `Effect.throttle` operator.
- Ensure all values in `Effect.throttle` come from the passed in
`scheduler`.
* Fix `Effect.throttle` tests, Use `sync` lock helperEffect.throttle data races and scheduler value return (#669)1 parent 30f3027 commit 65f1fa0
File tree
2 files changed
+44
-23
lines changed- Sources/ComposableArchitecture/Effects
- Tests/ComposableArchitectureTests
2 files changed
+44
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
28 | 26 | | |
29 | | - | |
30 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
31 | 32 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 33 | + | |
| 34 | + | |
37 | 35 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
48 | 54 | | |
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
52 | 58 | | |
| 59 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
| 37 | + | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
| |||
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
| 83 | + | |
| 84 | + | |
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
| 90 | + | |
| 91 | + | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| |||
124 | 132 | | |
125 | 133 | | |
126 | 134 | | |
| 135 | + | |
| 136 | + | |
127 | 137 | | |
128 | 138 | | |
129 | 139 | | |
130 | 140 | | |
131 | 141 | | |
132 | 142 | | |
133 | 143 | | |
| 144 | + | |
| 145 | + | |
134 | 146 | | |
135 | 147 | | |
136 | 148 | | |
| |||
156 | 168 | | |
157 | 169 | | |
158 | 170 | | |
| 171 | + | |
| 172 | + | |
159 | 173 | | |
160 | 174 | | |
161 | 175 | | |
| |||
0 commit comments