Repository navigation
feat: report and reuse a sequencer's owning thread - #227
Merged
Merged
Conversation
Add IThreadAffineSequencer to ReactiveUI.Primitives.Core. Its CheckAccess reports whether the calling thread owns a sequencer. The Avalonia, WPF, WinForms, MAUI, WinUI, Android and Apple sequencers implement it in both flavours. Each owner-backed sequencer gains a static For(owner) that returns one sequencer per dispatcher, control, dispatcher queue or looper. It returns the shared instance for that instance's own owner. WitnessOnSignal gains an owner-aware constructor and a WitnessOnOwner extension. They deliver inline when the calling thread owns the sequencer and nothing is waiting, and queue otherwise, so a notification never overtakes one that is already waiting.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #227 +/- ##
=======================================
Coverage 99.78% 99.78%
=======================================
Files 785 785
Lines 24850 24923 +73
Branches 2946 2957 +11
=======================================
+ Hits 24796 24869 +73
Misses 54 54 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Sequencers that run work on a UI thread can now say whether the calling thread owns them, and hand back one shared sequencer per UI owner.
IThreadAffineSequencer.CheckAccess()in ReactiveUI.Primitives.Core reports whether the calling thread owns a sequencer. The Avalonia, WPF, WinForms, MAUI, WinUI, Android and Apple sequencers implement it in both flavours.For(owner)onAvaloniaScheduler,DispatcherSequencer,ControlSequencer,MauiDispatcherSequencer,DispatcherQueueSequencerandHandlerSequencerreturns one cached sequencer per dispatcher, control, dispatcher queue or looper, and returns the shared instance for its own owner.WitnessOnOwner(sequencer)and a newWitnessOnSignal<T>constructor deliver a notification inline when the caller owns the sequencer and nothing is waiting; anything raised later queues behind what is already waiting.Why
ReactiveUI.Binding routes every view write onto the thread that owns the view. Each platform currently does that through its own dispatcher code, because no sequencer can say which thread owns it. With
CheckAccessandFor, the binding platform packages route through these sequencers instead, starting with a new Avalonia package for reactiveui/ReactiveUI.Avalonia#216.Breaking changes
None. Every change adds API; existing constructors,
Main,CurrentandInstancebehave as before.How this was verified
Tests cover the new operator path and the Avalonia and MAUI sequencers'
CheckAccessandFor. The WPF, WinForms, WinUI, Android and Apple sequencer changes compile here but their tests only run on Windows or a device, so CI is their first run. The Apple PublicAPI baselines were edited by hand because Apple heads do not build on Linux.Notes for the reviewer
Start with
WitnessOnSignal{T}.cs: the inline path only runs when an owner is passed, so the existing constructor is unchanged. TheForlookups hold sequencers in aConditionalWeakTablekeyed by the owner. Blazor and Wasm do not implementIThreadAffineSequencer: the Blazor sequencer has no dispatcher to ask, and Wasm has no owning thread. Some PublicAPI baselines were re-sorted by the regeneration tool without API changes.Checklist