It would be beneficial ifAsapScheduler,AsapAction,AsyncScheduler, andAsyncAction were exposed in the public API. This would help address an inherent problem when using the out-of-the-box RxJSasapScheduler within Angular applications. Current BehaviorInternally, theAsapScheduler usessetImmediate to schedule actions on the microtask queue. However, it only invokessetImmediate once per microtask tick. Subsequent actions scheduled during the same tick are simply appended to the internal actions array without triggering anothersetImmediate call. All actions are then flushed together during the same tick. The Problem in Angular ContextThis 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 theNgZone during the same microtask tick, the zone context of thefirst scheduled action determines the zone in whichall 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 theNgZone: - Components created during that change detection will have their host bindings and event listeners attached outside the
NgZone - Events emitted from these components will no longer trigger application-level change detection
- This defeats the core purpose of Angular's
NgZone mechanism
Proposed SolutionTo resolve this issue, we need the ability to create separate scheduler instances for different zone contexts: constasapOutsideNgScheduler:AsapScheduler=newAsapScheduler(AsapAction); However, this solution requires access to theAsapScheduler andAsapAction classes, which are currently internal to RxJS. RequestPlease consider exposingAsapScheduler,AsapAction,AsyncScheduler, andAsyncAction as part of the public API to enable Angular developers to properly manage zone contexts when using schedulers. |