abortabort
v0.2.0
Published
Simple AbortController wrapper that makes it easy to nest signals
Downloads
6
Maintainers
Readme
abortabort
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 to0.5
, it will not abort. If you want to set it to abort, you should set it to0.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
- Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
- MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)
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.