summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/services/ngzone-scheduler.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/shared/services/ngzone-scheduler.service.ts')
-rw-r--r--src/pybind/mgr/dashboard/frontend/src/app/shared/services/ngzone-scheduler.service.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/ngzone-scheduler.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/ngzone-scheduler.service.ts
new file mode 100644
index 000000000..a2c6b6c95
--- /dev/null
+++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/ngzone-scheduler.service.ts
@@ -0,0 +1,48 @@
+import { Injectable, NgZone } from '@angular/core';
+
+import { asyncScheduler, SchedulerLike, Subscription } from 'rxjs';
+
+abstract class NgZoneScheduler implements SchedulerLike {
+ protected scheduler = asyncScheduler;
+
+ constructor(protected zone: NgZone) {}
+
+ abstract schedule(...args: any[]): Subscription;
+
+ now(): number {
+ return this.scheduler.now();
+ }
+}
+
+@Injectable({
+ providedIn: 'root'
+})
+export class LeaveNgZoneScheduler extends NgZoneScheduler {
+ constructor(zone: NgZone) {
+ super(zone);
+ }
+
+ schedule(...args: any[]): Subscription {
+ return this.zone.runOutsideAngular(() => this.scheduler.schedule.apply(this.scheduler, args));
+ }
+}
+
+@Injectable({
+ providedIn: 'root'
+})
+export class EnterNgZoneScheduler extends NgZoneScheduler {
+ constructor(zone: NgZone) {
+ super(zone);
+ }
+
+ schedule(...args: any[]): Subscription {
+ return this.zone.run(() => this.scheduler.schedule.apply(this.scheduler, args));
+ }
+}
+
+@Injectable({
+ providedIn: 'root'
+})
+export class NgZoneSchedulerService {
+ constructor(public leave: LeaveNgZoneScheduler, public enter: EnterNgZoneScheduler) {}
+}