@azure/abort-controller package

클래스

AbortError

이 오류는 비동기 작업이 중단된 경우 throw됩니다. 오류의 이름 속성이 name일치하는 "AbortError" 테스트하여 이 오류를 확인합니다.

예제

import { AbortError } from "@azure/abort-controller";

async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {
  if (options.abortSignal.aborted) {
    throw new AbortError();
  }

  // do async work
}

const controller = new AbortController();
controller.abort();
try {
  doAsyncWork({ abortSignal: controller.signal });
} catch (e) {
  if (e instanceof Error && e.name === "AbortError") {
    // handle abort error here.
  }
}

인터페이스

AbortSignalLike

"abort" 이벤트가 발생할 때 요청을 중단할 수 있습니다. 브라우저 기본 제공 AbortSignal 및 일반 폴리필과 호환됩니다.