2.1.1 • Published 6 days ago

@azure/abort-controller v2.1.1

Weekly downloads
508,867
License
MIT
Repository
github
Last release
6 days ago

Azure Abort Controller library for JS

The @azure/abort-controller package provides AbortController and AbortSignal classes. These classes are compatible with the AbortController built into modern browsers and the AbortSignal used by fetch. Use the AbortController class to create an instance of the AbortSignal class that can be used to cancel an operation in an Azure SDK that accept a parameter of type AbortSignalLike.

Getting started

Installation

Install this libray using npm as follows

npm install @azure/abort-controller

Key Concepts

Use the 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. AbortController.timeout(100). that is cancelled after 100 milliseconds.

Calling abort() on the instantiated AbortController invokes the registered abort event listeners on the associated AbortSignal. Any subsequent calls to abort() on the same controller will have no effect.

The AbortSignal.none static property returns an AbortSignal that can not be aborted.

Multiple instances of an AbortSignal can be linked so that calling abort() on the parent signal, aborts all linked signals. This linkage is one-way, meaning that a parent signal can affect a linked signal, but not the other way around. To link AbortSignals together, pass in the parent signals to the AbortController constructor.

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

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

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

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

Example 2 - Aborting with timeout

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

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

Example 3 - Aborting sub-tasks

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

const allTasksController = new AbortController();

const subTask1 = new AbortController(allTasksController.signal);
const subtask2 = new AbortController(allTasksController.signal);

allTasksController.abort(); // aborts allTasksSignal, subTask1, subTask2
subTask1.abort(); // aborts only subTask1

Example 4 - Aborting with parent signal or timeout

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

const allTasksController = new AbortController();

// create a subtask controller that can be aborted manually,
// or when either the parent task aborts or the timeout is reached.
const subTask = new AbortController(allTasksController.signal, AbortController.timeout(100));

allTasksController.abort(); // aborts allTasksSignal, subTask
subTask.abort(); // aborts only subTask

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

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.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Impressions

@azure/event-hubs@azure/cosmos@azure/identity@azure/service-bus@azure/keyvault-keys@azure/keyvault-certificatesnpm-deploy-sample-uhjindorsavi-storagevscode-azureappservice-la@everything-registry/sub-chunk-106nanogl-gltfmock-event-hubdwtest-computegithub-actions.warp-cache@itwin/reality-data-transfer@itwin/imodels-access-backendvscode-azureappserviceuppy-azure-blob@microsoft/azure-artifact-storage@microsoft/vscode-azext-azureappservice@nikhlagrwl/identityskyeye-librarysstchurazure-storage-blob@azure/arm-liftrqumulo@marygao/core-lro@soyjak/utils@useblacksmith/cache@3squared/forge-ui@3squared/forge-ui-3asbmodules@ardiffact/azure-artifact-storageazure-iot-device@actions/cache@azure-tools/communication-alpha-ids@azure-tools/communication-domain-verification@azure-tools/communication-recipient-verification@azure-tools/communication-short-codes@azure-tools/communication-tiering@azure-tools/communication-toll-free-verification@azure-rest/ai-document-intelligence@azure-rest/core-client@azure-rest/developer-devcenter@azure-rest/health-insights-cancerprofiling@azure-rest/health-insights-clinicalmatching@azure-rest/health-insights-radiologyinsights@azure-rest/load-testing@azure-rest/openai@azure-rest/purview-sharing@azure/arm-hybridcompute@azure/arm-hybridcontainerservice@azure/arm-hybridkubernetes@azure/arm-hybridnetwork@azure/arm-imagebuilder@azure/arm-iotcentral@azure/arm-iothub@azure/arm-iothub-profile-2020-09-01-hybrid@azure/arm-keyvault@azure/arm-keyvault-profile-2020-09-01-hybrid@azure/arm-kubernetesconfiguration@azure/arm-kusto@azure/arm-labservices@azure/arm-largeinstance@azure/arm-loadtesting@azure/arm-loadtestservice@azure/arm-botservice@azure/arm-cdn@azure/arm-chaos@azure/arm-cognitiveservices@azure/arm-communication@azure/arm-compute@azure/arm-compute-profile-2020-09-01-hybrid@azure/arm-confidentialledger@azure/arm-confluent@azure/arm-connectedvmware@azure/arm-elastic@azure/arm-elasticsan@azure/arm-eventgrid@azure/arm-eventhub@azure/arm-eventhub-profile-2020-09-01-hybrid@azure/arm-extendedlocation@azure/arm-containerinstance@azure/arm-containerregistry@azure/arm-containerservice@azure/arm-containerservicefleet@azure/arm-cosmosdb@azure/arm-dataprotection@azure/arm-defendereasm@azure/arm-deploymentmanager@azure/arm-devcenter@azure/arm-deviceprovisioningservices@azure/arm-deviceupdate@azure/arm-devspaces@azure/arm-devtestlabs@azure/arm-digitaltwins@azure/arm-dns@azure/arm-dns-profile-2020-09-01-hybrid@azure/arm-dnsresolver@azure/arm-domainservices@azure/arm-dynatrace@azure/arm-frontdoor
2.1.1

8 days ago

2.1.0

15 days ago

2.0.0

3 months ago

1.1.0

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-preview.2

5 years ago

1.0.0-preview.1

5 years ago