@azure/abort-controller

中文文档
2.2.0发布于 2026/07/14MITTypeScriptESM + CJS近 30 天下载 1.3亿

Microsoft Azure SDK for JavaScript - Aborter

原始使用文档
文档目录9 节
  1. Getting started
  2. Installation
  3. Key Concepts
  4. Examples
  5. Example 1 - basic usage
  6. Example 2 - Aborting with timeout
  7. Next steps
  8. Troubleshooting
  9. Contributing

Azure Abort Controller client library for JavaScript

The @azure/abort-controller package provides AbortSignalLike interface and AbortError classes to make it easier to work with the AbortController and the AbortSignal used by fetch built into modern JavaScript platforms.

Customers of Azure SDK for JavaScript in general do not need to use this library. Instead they use AbortController and AbortSignal provided by their platforms and pass the abort signals to Azure SDK operations.

Key links:

Getting started

Installation

Install this library using npm as follows

npm install @azure/abort-controller

Key Concepts

Use AbortController to create an AbortSignal which can then be passed to Azure SDK operations to cancel pending work. The AbortSignal can be accessed via the signal property on an instantiated AbortController. An AbortSignal can also be returned directly from a static method, e.g. AbortSignal.timeout(100). that is cancelled after 100 milliseconds.

Examples

The below examples assume that doAsyncWork is a function that takes a bag of properties, one of which is of the abort signal.

Example 1 - basic usage

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

  // do async work
}

const controller = new AbortController();
doAsyncWork({ abortSignal: controller.signal });

// at some point later
controller.abort();

Example 2 - Aborting with timeout

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

  // do async work
}

const signal = AbortSignal.timeout(1000);
doAsyncWork({ abortSignal: signal });

Next steps

You can build and run the tests locally by executing npm run test. Explore the test folder to see advanced usage and behavior of the public classes.

Troubleshooting

If you run into issues while using this library, please feel free to file an issue.

Contributing

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.

版本与发布记录

@azure/abort-controller 共发布 536 个版本,首次发布于 2019/06/28;过去 12 个月发布了 34 个版本。

版本发布日期距今
2.2.0latest2026/07/143 个月前
2.1.3-alpha.20260306.4dev2026/03/078 个月前
2.1.3-alpha.20260305.62026/03/068 个月前
2.1.3-alpha.20260227.22026/02/288 个月前
2.1.3-alpha.20260226.12026/02/278 个月前
2.1.3-alpha.20260224.32026/02/258 个月前

关于 @azure/abort-controller 的常见问题

@azure/abort-controller 是什么?

Microsoft Azure SDK for JavaScript - Aborter

如何安装 @azure/abort-controller?

在项目目录运行 npm install @azure/abort-controller,或使用 pnpm add / yarn add / bun add。

@azure/abort-controller 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@azure/abort-controller 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@azure/abort-controller 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@azure/abort-controller 可以商用吗?

@azure/abort-controller 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@azure/abort-controller 的下载量有多少?

根据 npm 官方下载统计,@azure/abort-controller 在 2026/10/08 – 2026/11/06 这 30 天内被下载 127,597,605 次,日均约 4,253,254 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@azure/abort-controller 还在维护吗?

最新版本 2.2.0 发布于 2026/07/14(3 个月前);至今共发布 536 个版本,其中过去 12 个月发布了 34 个;首次发布于 2019/06/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。