{"name":"any-signal","version":"2.1.0","description":"Combines an array of AbortSignals into a single signal that is aborted when any signal is","main":"index.js","types":"index.d.ts","scripts":{"test":"npm run lint && nyc --reporter=lcov --reporter=text ava --verbose","lint":"standard"},"keywords":[],"author":{"name":"Jacob Heun"},"license":"MIT","dependencies":{"abort-controller":"^3.0.0","native-abort-controller":"0.0.3"},"devDependencies":{"ava":"^3.11.1","nyc":"^15.1.0","p-defer":"^3.0.0","standard":"^14.3.1"},"repository":{"type":"git","url":"git+https://github.com/jacobheun/any-signal.git"},"bugs":{"url":"https://github.com/jacobheun/any-signal/issues"},"homepage":"https://github.com/jacobheun/any-signal#readme","gitHead":"3cb97cf92767e0219465d589129f6abdf875b11d","_id":"any-signal@2.1.0","_nodeVersion":"14.5.0","_npmVersion":"6.14.5","dist":{"integrity":"sha512-RzrSTVJLe4BK8jk5kw94mXNsMfG6D0I12Mv724xjbqb+9MQn5lWwnzd82Xo5iH0/aBSxYsEUNTLp2ncmzkYaCw==","shasum":"8736f59e0bcb9a0f4b6af3995e520bd789fdc69d","tarball":"http://registry-npm.ywwl.com/any-signal/download/any-signal-2.1.0.tgz","fileCount":4,"unpackedSize":4837,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfexAWCRA9TVsSAnZWagAAoKMQAKEwsmUS1juP5hLTE6TV\nAUSy2ztap/59PHWQurW8xDkezpqwTQD1GjKWC41y6XaitHMTTm2BdUrzTLno\nhcP9aPYze0GW3Ecqn4nfcIGJeDw1/SICHD9K7KD0pO9DveemtqO3+YyZxU5z\nI+4I0kwXdhVj2p91neYxdznE35Qq84JfYbARz8eE7/0+iZvHgNi5LjObGQdo\ncksKCKcH9fDRl1RLe7tTxNgSd/pp8vBpiRwK9AjVMExtHslEuOHZUmoXD9Gr\n8FE9RGsy6IUj10+of/QVadbySfC03OFuZlMSxWWbg0/dlPsopccAzYt5BoJY\nSk2cb/QfC2HmX+RzKkGqPXVjDPIlh4znHUPGw+y3te3APWT7x6p7kzZXYyne\n0z4818BOci/m868T6aTp2m2XlwwXUWopXMDov7R9sWYgaTuyi7F0NK/trGM0\nfG+SsPeeKv2syeX1wM1MofYbETyFhlSt51m2TeiOACWEPB7AQspbSQvr1QdC\nW3gL4AWjrSMz1tVhALJ14f7xzqLhGx5fVFhfrNZWYYMO56HNG/xB4AeAOHpE\nMdZbVHqmCFMByorbz9CAvnxTq43NHu9M96OUUuybR4T67OOEDLM5Oiu1lX+p\nSkQUIcA9ZNq7cmYSOjdQ6en0IZVIX4MDrXlBHT2g6REufKRM/zqHaVomRTFp\noVyj\r\n=PRM3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDsT2jvCPWe/zB/ghOKjRWwX2nKFeLYBHdfMVVOyMEj8AIgIPUxX/sNbpBtKzilw69fHeFujtSBcGtvEpJVdaaQqeQ="}],"size":2222,"noattachment":false,"key":"/any-signal/-/any-signal-2.1.0.tgz"},"maintainers":[{"name":"jacobheun","email":"jacobheun@gmail.com"}],"_npmUser":{"name":"jacobheun","email":"jacobheun@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/any-signal_2.1.0_1601900566432_0.36682742346342323"},"_hasShrinkwrap":false,"readme":"# any-signal <!-- omit in toc -->\n\n[![codecov](https://img.shields.io/codecov/c/github/jacobheun/any-signal.svg?style=flat-square)](https://codecov.io/gh/jacobheun/any-signal)\n[![CI](https://img.shields.io/github/actions/workflow/status/jacobheun/any-signal/js-test-and-release.yml?branch=master\\&style=flat-square)](https://github.com/jacobheun/any-signal/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)\n\n> Combines an array of AbortSignals into a single signal that is aborted when any signal is\n\n## Table of contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [Browser `<script>` tag](#browser-script-tag)\n- [Usage](#usage)\n- [API](#api)\n  - [`anySignal(signals)`](#anysignalsignals)\n    - [Parameters](#parameters)\n    - [Returns](#returns)\n  - [`ClearableSignal.clear()`](#clearablesignalclear)\n- [Acknowledgements](#acknowledgements)\n- [API Docs](#api-docs)\n- [License](#license)\n- [Contribution](#contribution)\n\n## Install\n\n```console\n$ npm i any-signal\n```\n\n### Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `AnySignal` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/any-signal/dist/index.min.js\"></script>\n```\n\n## Usage\n\n```js\nimport { anySignal } from 'any-signal'\n\nconst userController = new AbortController()\nconst timeoutController = new AbortController()\n\nconst combinedSignal = anySignal([userController.signal, timeoutController.signal])\ncombinedSignal.addEventListener('abort', () => console.log('Abort!'))\n\n// Abort after 1 second\nconst timeoutId = setTimeout(() => timeoutController.abort(), 1000)\n\n// The user or the timeout can now abort the action\nawait performSomeAction({ signal: combinedSignal })\nclearTimeout(timeoutId)\n\n// Clear will clean up internal event handlers\ncombinedSignal.clear()\n```\n\n## API\n\n### `anySignal(signals)`\n\n#### Parameters\n\n| Name    | Type                                                                                 | Description                                                         |\n| ------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------- |\n| signals | Array<[`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)> | The Signals that will be observed and mapped to the returned Signal |\n\n#### Returns\n\n| Type                                                                              | Description                                                                                                                                   |\n| --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |\n| [`ClearableSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | A Signal that will be aborted as soon as any one of its parent signals are aborted. Extends AbortSignal with the `clear` function for cleanup |\n\nThe returned [`ClearableSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) will only be aborted once, and as soon as one of its parent signals is aborted.\n\n### `ClearableSignal.clear()`\n\nRemoves all internal event handlers. This **must** be called after abort has been called, or the signals have successfully executed, otherwise there is a risk of leaking event handlers.\n\n## Acknowledgements\n\nThe anySignal function is taken from a [comment by jakearchibald](https://github.com/whatwg/fetch/issues/905#issuecomment-491970649)\n\n## API Docs\n\n- <https://jacobheun.github.io/any-signal>\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n## Contribution\n\nUnless 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.\n","publish_time":1601900566533,"_cnpm_publish_time":1601900566533,"dist-tags":{"latest":"4.2.0"}}