Socket
Socket
Sign inDemoInstall

@azure/abort-controller

Package Overview
Dependencies
1
Maintainers
2
Versions
232
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @azure/abort-controller

Microsoft Azure SDK for JavaScript - Aborter


Version published
Weekly downloads
7.1M
decreased by-18.55%
Maintainers
2
Created
Weekly downloads
 

Package description

What is @azure/abort-controller?

The @azure/abort-controller npm package provides a way to use AbortController and AbortSignal, which are interfaces for abortable operations, in the Azure SDKs. These are particularly useful for cancelling asynchronous operations in JavaScript, such as network requests or long-running processes.

What are @azure/abort-controller's main functionalities?

Creating an AbortController and AbortSignal

This feature allows you to create an instance of AbortController and retrieve its AbortSignal. The signal can then be passed to operations that support cancellation.

const { AbortController } = require('@azure/abort-controller');
const controller = new AbortController();
const signal = controller.signal;

Aborting an operation

This feature enables you to abort an operation by calling the `abort` method on the controller. Any operation listening to the associated signal will be cancelled.

controller.abort();

Listening for an abort signal

This feature allows you to listen for an abort event on the AbortSignal. This is useful for performing cleanup or rollback actions when an operation is cancelled.

signal.addEventListener('abort', () => {
  console.log('Operation aborted!');
});

Other packages similar to @azure/abort-controller

Readme

Source

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

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

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

Example 2 - Aborting with timeout

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

Next steps

You can build and run the tests locally by executing rushx 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.

Impressions

Keywords

FAQs

Last updated on 11 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc