Request for Public API Access to RxJS Schedulers #7579
kramar
started this conversation in
Ideas / Feature request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
It would be beneficial if
AsapScheduler,AsapAction,AsyncScheduler, andAsyncActionwere exposed in the public API. This would help address an inherent problem when using the out-of-the-box RxJSasapSchedulerwithin Angular applications.Current Behavior
Internally, the
AsapSchedulerusessetImmediateto schedule actions on the microtask queue. However, it only invokessetImmediateonce per microtask tick. Subsequent actions scheduled during the same tick are simply appended to the internal actions array without triggering anothersetImmediatecall. All actions are then flushed together during the same tick.The Problem in Angular Context
This batching behavior can cause critical issues in Angular applications when actions are scheduled from different zone contexts. Specifically:
Zone Context Locking: If actions are scheduled both inside and outside the
NgZoneduring the same microtask tick, the zone context of the first scheduled action determines the zone in which all subsequent actions will execute.Change Detection Outside NgZone: This becomes particularly problematic when a scheduled action triggers change detection. If that change detection runs outside the
NgZone:NgZoneNgZonemechanismProposed Solution
To resolve this issue, we need the ability to create separate scheduler instances for different zone contexts:
However, this solution requires access to the
AsapSchedulerandAsapActionclasses, which are currently internal to RxJS.Request
Please consider exposing
AsapScheduler,AsapAction,AsyncScheduler, andAsyncActionas part of the public API to enable Angular developers to properly manage zone contexts when using schedulers.Beta Was this translation helpful? Give feedback.
All reactions