Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-abort-controller

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-abort-controller

fast abort controller implementation that can be used as a ponyfill/polyfill

  • 4.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40
increased by8.11%
Maintainers
1
Weekly downloads
 
Created
Source

FastAbortController

fast abort controller implementation that can be used as a ponyfill/polyfill

Installation

npm i --save fast-abort-controller

Usage

Supports both ESM and CommonJS
// esm
import AbortController from 'fast-abort-controller'
// commonjs
const AbortController = require('fast-abort-controller').default

Example with Fetch (which supports abort signals)

import AbortController from 'fast-abort-controller'

const controller = new AbortController()

const signal = controller.signal

function cancel() {
  signal.abort()
}

try {
  await fetch('codeshare.io', { signal })
  console.log('request success')
} catch (err) {
  if (err.name === 'AbortError') {
    console.warn('request aborted')
  } else {
    console.error('request error', err)
  }
}

// ...

Example with raceAbort

import { readFile } from 'fs/promises'

import AbortController from 'fast-abort-controller'
import raceAbort from 'race-abort'

const controller = new AbortController()

const signal = controller.signal

function cancel() {
  signal.abort()
}

try {
  // readFile doesnt support cancellation so we wrap it with raceAbort provided by another module 'race-abort'
  await raceAbort(readFile('foo/bar/qux'), signal)
  console.log('request success')
} catch (err) {
  if (err.name === 'AbortError') {
    console.warn('request aborted')
  } else {
    console.error('request error', err)
  }
}

License

MIT

Keywords

FAQs

Package last updated on 17 Apr 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc