(bucket: IdleBucket, options?: IdleRequestOptions)
| 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) { |
no test coverage detected