source: trip-planner-front/node_modules/zone.js/fesm2015/task-tracking.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[6a3a178]1'use strict';
2/**
3 * @license Angular v12.0.0-next.0
4 * (c) 2010-2020 Google LLC. https://angular.io/
5 * License: MIT
6 */
7/**
8 * @license
9 * Copyright Google LLC All Rights Reserved.
10 *
11 * Use of this source code is governed by an MIT-style license that can be
12 * found in the LICENSE file at https://angular.io/license
13 */
14/**
15 * A `TaskTrackingZoneSpec` allows one to track all outstanding Tasks.
16 *
17 * This is useful in tests. For example to see which tasks are preventing a test from completing
18 * or an automated way of releasing all of the event listeners at the end of the test.
19 */
20class TaskTrackingZoneSpec {
21 constructor() {
22 this.name = 'TaskTrackingZone';
23 this.microTasks = [];
24 this.macroTasks = [];
25 this.eventTasks = [];
26 this.properties = { 'TaskTrackingZone': this };
27 }
28 static get() {
29 return Zone.current.get('TaskTrackingZone');
30 }
31 getTasksFor(type) {
32 switch (type) {
33 case 'microTask':
34 return this.microTasks;
35 case 'macroTask':
36 return this.macroTasks;
37 case 'eventTask':
38 return this.eventTasks;
39 }
40 throw new Error('Unknown task format: ' + type);
41 }
42 onScheduleTask(parentZoneDelegate, currentZone, targetZone, task) {
43 task['creationLocation'] = new Error(`Task '${task.type}' from '${task.source}'.`);
44 const tasks = this.getTasksFor(task.type);
45 tasks.push(task);
46 return parentZoneDelegate.scheduleTask(targetZone, task);
47 }
48 onCancelTask(parentZoneDelegate, currentZone, targetZone, task) {
49 const tasks = this.getTasksFor(task.type);
50 for (let i = 0; i < tasks.length; i++) {
51 if (tasks[i] == task) {
52 tasks.splice(i, 1);
53 break;
54 }
55 }
56 return parentZoneDelegate.cancelTask(targetZone, task);
57 }
58 onInvokeTask(parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs) {
59 if (task.type === 'eventTask')
60 return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs);
61 const tasks = this.getTasksFor(task.type);
62 for (let i = 0; i < tasks.length; i++) {
63 if (tasks[i] == task) {
64 tasks.splice(i, 1);
65 break;
66 }
67 }
68 return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs);
69 }
70 clearEvents() {
71 while (this.eventTasks.length) {
72 Zone.current.cancelTask(this.eventTasks[0]);
73 }
74 }
75}
76// Export the class so that new instances can be created with proper
77// constructor params.
78Zone['TaskTrackingZoneSpec'] = TaskTrackingZoneSpec;
Note: See TracBrowser for help on using the repository browser.