(
source: string,
data: TaskData | undefined,
originalImpl: any,
self: any,
args: any[],
ac?: AbortController,
)
| 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 |
no test coverage detected
searching dependent graphs…