MCPcopy Index your code
hub / github.com/angular/angular-cli / promiseWithAbort

Function promiseWithAbort

packages/angular/ssr/src/utils/promise.ts:22–50  ·  view source on GitHub ↗
(
  promise: Promise<T>,
  signal: AbortSignal,
  errorMessagePrefix: string,
)

Source from the content-addressed store, hash-verified

20 * @throws {AbortError} If the `AbortSignal` is triggered before the `promise` resolves.
21 */
22export function promiseWithAbort<T>(
23 promise: Promise<T>,
24 signal: AbortSignal,
25 errorMessagePrefix: string,
26): Promise<T> {
27 return new Promise<T>((resolve, reject) => {
28 const abortHandler = () => {
29 reject(
30 new DOMException(`${errorMessagePrefix} was aborted.\n${signal.reason}`, 'AbortError'),
31 );
32 };
33
34 // Check for abort signal
35 if (signal.aborted) {
36 abortHandler();
37
38 return;
39 }
40
41 signal.addEventListener('abort', abortHandler, { once: true });
42
43 promise
44 .then(resolve)
45 .catch(reject)
46 .finally(() => {
47 signal.removeEventListener('abort', abortHandler);
48 });
49 });
50}

Callers 3

promise_spec.tsFile · 0.90
handleMethod · 0.90

Calls 1

abortHandlerFunction · 0.85

Tested by

no test coverage detected