MCPcopy
hub / github.com/angular/angular / scheduleBucket

Method scheduleBucket

packages/core/src/defer/idle_scheduler.ts:98–134  ·  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 this.cancelBucket(bucket);
106
107 for (const cb of bucket.queue) {
108 cb();
109 // _tick here is an optimized change detection check and is safe to call here.
110 // We also account for the time it takes to run change detection
111 // for the newly-created view as a part of the same idle callback.
112 this.applicationRef._tick();
113 bucket.queue.delete(cb);
114 this.callbackBucket.delete(cb);
115
116 if (deadline && deadline.timeRemaining() === 0 && !deadline.didTimeout) {
117 break;
118 }
119 }
120
121 if (bucket.queue.size > 0) {
122 this.scheduleBucket(bucket, options);
123 } else {
124 this.buckets.delete(key);
125 }
126 };
127
128 // Ensure that the callback runs in the NgZone since
129 // the `requestIdleCallback` is not currently patched by Zone.js.
130 bucket.idleId = this.idleService.requestOnIdle(
131 (deadline) => this.ngZone.run(() => callback(deadline)),
132 options,
133 );
134 }
135
136 private cancelBucket(bucket: IdleBucket) {
137 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