MCPcopy Index your code
hub / github.com/angular/angular / createFetchTask

Function createFetchTask

packages/zone.js/lib/common/fetch.ts:35–91  ·  view source on GitHub ↗
(
      source: string,
      data: TaskData | undefined,
      originalImpl: any,
      self: any,
      args: any[],
      ac?: AbortController,
    )

Source from the content-addressed store, hash-verified

33 const placeholder = function () {};
34
35 const createFetchTask = (
36 source: string,
37 data: TaskData | undefined,
38 originalImpl: any,
39 self: any,
40 args: any[],
41 ac?: AbortController,
42 ) =>
43 new Promise((resolve, reject) => {
44 const task = Zone.current.scheduleMacroTask(
45 source,
46 placeholder,
47 data,
48 () => {
49 // The promise object returned by the original implementation passed into the
50 // function. This might be a `fetch` promise, `Response.prototype.json` promise,
51 // etc.
52 let implPromise;
53 let zone = Zone.current;
54
55 try {
56 (zone as any)[fetchTaskScheduling] = true;
57 implPromise = originalImpl.apply(self, args);
58 } catch (error) {
59 reject(error);
60 return;
61 } finally {
62 (zone as any)[fetchTaskScheduling] = false;
63 }
64
65 if (!(implPromise instanceof ZoneAwarePromise)) {
66 let ctor = implPromise.constructor;
67 if (!ctor[symbolThenPatched]) {
68 api.patchThen(ctor);
69 }
70 }
71
72 implPromise.then(
73 (resource: any) => {
74 if (task.state !== 'notScheduled') {
75 task.invoke();
76 }
77 resolve(resource);
78 },
79 (error: any) => {
80 if (task.state !== 'notScheduled') {
81 task.invoke();
82 }
83 reject(error);
84 },
85 );
86 },
87 () => {
88 ac?.abort();
89 },
90 );
91 });
92

Callers 1

patchFetchFunction · 0.85

Calls 7

rejectFunction · 0.85
scheduleMacroTaskMethod · 0.65
applyMethod · 0.65
thenMethod · 0.65
invokeMethod · 0.65
abortMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…