Commit 303d184
authored
Fix for 4280 interaction async handler scheduling (#4351)
<!-- Please be sure to read our [Contribute
guide](https://www.reactiveui.net/contribute/index.html) before opening
a PR. -->
## What kind of change does this PR introduce?
<!-- Bug fix, feature, docs update, refactor, ci, ... -->
Fix
## What is the current behavior?
<!-- You can also link to an open issue here. Use "Closes #123" to
auto-close on merge. -->
Closes #4280
## What is the new behavior?
<!-- If this is a feature change -->
This pull request refactors the `Interaction` handler registration and
execution logic in `ReactiveUI` to improve consistency, reliability, and
testability, especially around asynchronous handler scenarios. It
introduces a unified handler registration core, ensures asynchronous
handlers yield to the current context, and updates tests to use modern
async/await patterns. Several new tests are also added to verify
scheduler release behavior for both task-based and observable handlers.
**Core handler registration and async context improvements:**
* Introduced a private `RegisterHandlerCore` method to centralize
handler registration and disposal logic, replacing duplicated code in
`RegisterHandler` overloads.
[[1]](diffhunk://#diff-4c32538b51e31225de509d21d08ea6cfd573a7df738530957077df781d5d3ba9L90-R129)
[[2]](diffhunk://#diff-4c32538b51e31225de509d21d08ea6cfd573a7df738530957077df781d5d3ba9R172-R192)
* Added a private `YieldToCurrentContext` method to ensure asynchronous
handlers (both `Task` and `IObservable`-based) yield execution before
invoking user code, preventing scheduler trampoline issues and improving
nested interaction support.
[[1]](diffhunk://#diff-4c32538b51e31225de509d21d08ea6cfd573a7df738530957077df781d5d3ba9L90-R129)
[[2]](diffhunk://#diff-4c32538b51e31225de509d21d08ea6cfd573a7df738530957077df781d5d3ba9R172-R192)
**Test modernization and reliability:**
* Updated all relevant tests in `InteractionsTest.cs` to use
`async`/`await` and `ToTask()` instead of synchronous blocking
(`Wait()`/`FirstAsync().Wait()`), improving test reliability and better
reflecting real-world async usage.
[[1]](diffhunk://#diff-f2ed870457c71b058a31b5f78fde682cb52406c51bd54a6626d8f71de439d2ceL26-R28)
[[2]](diffhunk://#diff-f2ed870457c71b058a31b5f78fde682cb52406c51bd54a6626d8f71de439d2ceL45-R60)
[[3]](diffhunk://#diff-f2ed870457c71b058a31b5f78fde682cb52406c51bd54a6626d8f71de439d2ceL177-R258)
[[4]](diffhunk://#diff-f2ed870457c71b058a31b5f78fde682cb52406c51bd54a6626d8f71de439d2ceL210-R277)
[[5]](diffhunk://#diff-f2ed870457c71b058a31b5f78fde682cb52406c51bd54a6626d8f71de439d2ceL225-R304)
[[6]](diffhunk://#diff-f2ed870457c71b058a31b5f78fde682cb52406c51bd54a6626d8f71de439d2ceL264-R345)
* Marked the `InteractionsTest` class with `[NotInParallel]` to ensure
tests are not run in parallel, avoiding flakiness due to shared state.
**Expanded test coverage for async handler behavior:**
* Added tests to verify that both `Task`-based and `IObservable`-based
handlers release the current scheduler before executing user code,
ensuring nested interactions are not blocked and behave as expected.
**Test improvements for handler precedence and subscription timing:**
* Enhanced tests to more reliably detect when handlers are subscribed
and to ensure correct handler precedence, especially in asynchronous
scenarios, using `TaskCompletionSource` for precise subscription
tracking.
[[1]](diffhunk://#diff-f2ed870457c71b058a31b5f78fde682cb52406c51bd54a6626d8f71de439d2ceR100-R120)
[[2]](diffhunk://#diff-f2ed870457c71b058a31b5f78fde682cb52406c51bd54a6626d8f71de439d2ceR129)
These changes collectively make handler registration more robust,
improve async interaction patterns, and ensure that both the
implementation and test suite are future-proof and reliable.
## What might this PR break?
## Checklist
- [x] I have read the [Contribute
guide](https://www.reactiveui.net/contribute/index.html)
- [x] Tests have been added or updated (for bug fixes / features)
- [ ] Docs have been added or updated (for bug fixes / features)
- [x] Changes target the `main` branch
- [x] PR title follows [Conventional
Commits](https://www.conventionalcommits.org/)
## Additional information1 parent b54d29b commit 303d184
2 files changed
Lines changed: 162 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
102 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
103 | 113 | | |
104 | 114 | | |
105 | 115 | | |
106 | 116 | | |
107 | 117 | | |
108 | 118 | | |
109 | 119 | | |
110 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
111 | 128 | | |
112 | | - | |
113 | | - | |
| 129 | + | |
114 | 130 | | |
115 | 131 | | |
116 | 132 | | |
| |||
153 | 169 | | |
154 | 170 | | |
155 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
156 | 193 | | |
157 | 194 | | |
158 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | | - | |
27 | | - | |
| 27 | + | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | | - | |
46 | | - | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
52 | 54 | | |
53 | | - | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
66 | | - | |
67 | 68 | | |
68 | 69 | | |
69 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
70 | 78 | | |
| 79 | + | |
71 | 80 | | |
72 | | - | |
| 81 | + | |
73 | 82 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
78 | 88 | | |
79 | | - | |
80 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
81 | 94 | | |
82 | 95 | | |
83 | 96 | | |
| |||
95 | 108 | | |
96 | 109 | | |
97 | 110 | | |
| 111 | + | |
98 | 112 | | |
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
102 | 116 | | |
103 | 117 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
108 | 132 | | |
109 | 133 | | |
110 | 134 | | |
| |||
113 | 137 | | |
114 | 138 | | |
115 | 139 | | |
| 140 | + | |
116 | 141 | | |
117 | 142 | | |
118 | 143 | | |
| |||
139 | 164 | | |
140 | 165 | | |
141 | 166 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 167 | + | |
146 | 168 | | |
147 | 169 | | |
148 | 170 | | |
149 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
150 | 228 | | |
151 | 229 | | |
152 | 230 | | |
| |||
174 | 252 | | |
175 | 253 | | |
176 | 254 | | |
177 | | - | |
178 | | - | |
| 255 | + | |
| 256 | + | |
179 | 257 | | |
180 | 258 | | |
181 | 259 | | |
182 | 260 | | |
183 | | - | |
184 | | - | |
| 261 | + | |
| 262 | + | |
185 | 263 | | |
186 | 264 | | |
187 | 265 | | |
188 | 266 | | |
189 | 267 | | |
190 | | - | |
191 | | - | |
| 268 | + | |
| 269 | + | |
192 | 270 | | |
193 | 271 | | |
194 | 272 | | |
| |||
207 | 285 | | |
208 | 286 | | |
209 | 287 | | |
210 | | - | |
| 288 | + | |
211 | 289 | | |
212 | 290 | | |
213 | 291 | | |
| |||
222 | 300 | | |
223 | 301 | | |
224 | 302 | | |
225 | | - | |
| 303 | + | |
226 | 304 | | |
227 | 305 | | |
228 | | - | |
| 306 | + | |
229 | 307 | | |
230 | 308 | | |
231 | | - | |
| 309 | + | |
232 | 310 | | |
233 | 311 | | |
234 | | - | |
| 312 | + | |
235 | 313 | | |
236 | 314 | | |
237 | | - | |
| 315 | + | |
238 | 316 | | |
239 | 317 | | |
240 | 318 | | |
| |||
261 | 339 | | |
262 | 340 | | |
263 | 341 | | |
264 | | - | |
265 | | - | |
| 342 | + | |
| 343 | + | |
266 | 344 | | |
267 | 345 | | |
268 | | - | |
| 346 | + | |
269 | 347 | | |
270 | 348 | | |
271 | 349 | | |
272 | 350 | | |
273 | 351 | | |
274 | | - | |
275 | | - | |
| 352 | + | |
| 353 | + | |
276 | 354 | | |
277 | 355 | | |
278 | | - | |
| 356 | + | |
279 | 357 | | |
280 | 358 | | |
281 | 359 | | |
| |||
0 commit comments