MCPcopy Create free account
hub / github.com/angular/angular / scheduleBucket

Method scheduleBucket

packages/core/src/defer/idle_scheduler.ts:98–135  ·  view source on GitHub ↗
(bucket: IdleBucket, options?: IdleRequestOptions)

Source from the content-addressed store, hash-verified

96 }
97
98 private scheduleBucket(bucket: IdleBucket, options?: IdleRequestOptions) {
99 if (bucket.idleId !== null) {
100 return;
101 }
102
103 const key = getIdleRequestKey(options);
104 const callback = (deadline?: IdleDeadline) => {
105 // Keep idleId set during the drain to prevent re-entrant add() from scheduling redundant callbacks.
106 for (const cb of bucket.queue) {
107 cb();
108 // _tick here is an optimized change detection check and is safe to call here.
109 // We also account for the time it takes to run change detection
110 // for the newly-created view as a part of the same idle callback.
111 this.applicationRef._tick();
112 bucket.queue.delete(cb);
113 this.callbackBucket.delete(cb);
114
115 if (deadline && deadline.timeRemaining() === 0 && !deadline.didTimeout) {
116 break;
117 }
118 }
119
120 bucket.idleId = null;
121
122 if (bucket.queue.size > 0) {
123 this.scheduleBucket(bucket, options);
124 } else {
125 this.buckets.delete(key);
126 }
127 };
128
129 // Ensure that the callback runs in the NgZone since
130 // the `requestIdleCallback` is not currently patched by Zone.js.
131 bucket.idleId = this.idleService.requestOnIdle(
132 (deadline) => this.ngZone.run(() => callback(deadline)),
133 options,
134 );
135 }
136
137 private cancelBucket(bucket: IdleBucket) {
138 if (bucket.idleId !== null) {

Callers 2

addMethod · 0.95
callbackMethod · 0.95

Calls 4

getIdleRequestKeyFunction · 0.85
callbackFunction · 0.70
requestOnIdleMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected