New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

abortabort

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abortabort

Simple AbortController wrapper that makes it easy to nest signals

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

abortabort

codecov CI

Simple AbortController wrapper that makes it easy to nest signals

Table of contents

Features

  • Any dependants of an AbortAbort are aborted when it is aborted.
  • An AbortAbort can see how many of its dependants have been aborted
  • An attempt to add a dependant to an already aborted AbortAbort will immediately abort the dependant
  • An AbortAbort can abort if a certain percentage of its dependants have been aborted
  • An AbortAbort can abort if a certain number of its dependants have been aborted
  • An AbortAbort can be added to another as a dependant at any time

Install

$ npm i abortabort

Usage

See the tests for more usage examples than what is below.

option: successRatioLimit

A few things of note:

  • The success ratio is returned without any limiting on the precision. It is up to you to do so.
  • The comparison is done with actualSuccessRatio < successRatioLimit, so if you have two dependants, and you set the value to 0.5, it will not abort. If you want to set it to abort, you should set it to 0.51
import AbortAbort from 'abortabort'

const abortChild1 = new AbortAbort({ id: 'abortChild1' })
const abortChild2 = new AbortAbort({ id: 'abortChild2' })

/**
 * abortExample1 will abort on the first of any of these events:
 * * 15 seconds passes
 * * abortChild1 aborts (successRatio will be 0.50)
 */
const abortExample1 = new AbortAbort({ id: 'abortExample1', dependants: [abortChild1, abortChild2], timeout: 15000, successRatioLimit: 0.51 })

option: maximumFailedDependants

Set this to 0 to fail an AbortAbort anytime one of it's children aborts.


import AbortAbort from 'abortabort'
const abortChild1 = new AbortAbort({ id: 'abortChild1' })
const abortChild2 = new AbortAbort({ id: 'abortChild2' })
const abortChild3 = new AbortAbort({ id: 'abortChild3', dependants: [abortChild1], maximumFailedDependants: 0})

/**
 * abortExample1 will abort on the first of any of these events:
 * * 15 seconds passes
 * * abortChild3 aborts (maximumFailedDependants >= 0)
 * * abortChild1 aborts (it will cause abortChild3 to abort)
 */
const abortExample2 = new AbortAbort({ id: 'abortExample2', dependants: [abortChild1, abortChild2], maximumFailedDependants: 0 })

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Keywords

FAQs

Package last updated on 15 Mar 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