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

Method tick

packages/zone.js/lib/zone-spec/fake-async-test.ts:207–278  ·  view source on GitHub ↗
(
    millis: number = 0,
    doTick?: (elapsed: number) => void,
    tickOptions?: {
      processNewMacroTasksSynchronously: boolean;
    },
  )

Source from the content-addressed store, hash-verified

205 }
206
207 tick(
208 millis: number = 0,
209 doTick?: (elapsed: number) => void,
210 tickOptions?: {
211 processNewMacroTasksSynchronously: boolean;
212 },
213 ): void {
214 let finalTime = this._currentTickTime + millis;
215 let lastCurrentTime = 0;
216 tickOptions = Object.assign({processNewMacroTasksSynchronously: true}, tickOptions);
217 // we need to copy the schedulerQueue so nested timeout
218 // will not be wrongly called in the current tick
219 // https://github.com/angular/angular/issues/33799
220 const schedulerQueue = tickOptions.processNewMacroTasksSynchronously
221 ? this._schedulerQueue
222 : this._schedulerQueue.slice();
223 if (schedulerQueue.length === 0 && doTick) {
224 doTick(millis);
225 return;
226 }
227 while (schedulerQueue.length > 0) {
228 // clear requeueEntries before each loop
229 this._currentTickRequeuePeriodicEntries = [];
230 let current = schedulerQueue[0];
231 if (finalTime < current.endTime) {
232 // Done processing the queue since it's sorted by endTime.
233 break;
234 } else {
235 // Time to run scheduled function. Remove it from the head of queue.
236 let current = schedulerQueue.shift()!;
237 if (!tickOptions.processNewMacroTasksSynchronously) {
238 const idx = this._schedulerQueue.indexOf(current);
239 if (idx >= 0) {
240 this._schedulerQueue.splice(idx, 1);
241 }
242 }
243 lastCurrentTime = this._currentTickTime;
244 this._currentTickTime = current.endTime;
245 if (doTick) {
246 doTick(this._currentTickTime - lastCurrentTime);
247 }
248 let retval = current.func.apply(
249 global,
250 current.isRequestAnimationFrame ? [this._currentTickTime] : current.args,
251 );
252 if (!retval) {
253 // Uncaught exception in the current scheduled function. Stop processing the queue.
254 break;
255 }
256
257 // check is there any requeue periodic entry is added in
258 // current loop, if there is, we need to add to current loop
259 if (!tickOptions.processNewMacroTasksSynchronously) {
260 this._currentTickRequeuePeriodicEntries.forEach((newEntry) => {
261 let i = 0;
262 for (; i < schedulerQueue.length; i++) {
263 const currentEntry = schedulerQueue[i];
264 if (newEntry.endTime < currentEntry.endTime) {

Callers 3

tickToNextMethod · 0.95
flushPeriodicMethod · 0.95

Calls 4

doTickFunction · 0.85
indexOfMethod · 0.80
applyMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected