{"name":"race-event","version":"0.0.0","description":"Race an event against an AbortSignal","author":{"name":"Alex Potsides","email":"alex@achingbrain.net"},"license":"Apache-2.0 OR MIT","homepage":"https://github.com/achingbrain/race-event#readme","repository":{"type":"git","url":"git+https://github.com/achingbrain/race-event.git"},"bugs":{"url":"https://github.com/achingbrain/race-event/issues"},"type":"module","types":"./dist/src/index.d.ts","exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js"}},"eslintConfig":{"extends":"ipfs","parserOptions":{"project":true,"sourceType":"module"}},"release":{"branches":["main"],"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"breaking":true,"release":"major"},{"revert":true,"release":"patch"},{"type":"feat","release":"minor"},{"type":"fix","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","release":"patch"},{"type":"deps","release":"patch"},{"scope":"no-release","release":false}]}],["@semantic-release/release-notes-generator",{"preset":"conventionalcommits","presetConfig":{"types":[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"chore","section":"Trivial Changes"},{"type":"docs","section":"Documentation"},{"type":"deps","section":"Dependencies"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"]},"scripts":{"clean":"aegir clean","lint":"aegir lint","build":"aegir build","test":"aegir test","test:node":"aegir test -t node --cov","test:chrome":"aegir test -t browser --cov","test:chrome-webworker":"aegir test -t webworker","test:firefox":"aegir test -t browser -- --browser firefox","test:firefox-webworker":"aegir test -t webworker -- --browser firefox","release":"aegir release","dep-check":"aegir dep-check","docs":"aegir docs"},"devDependencies":{"aegir":"^41.0.0"},"_id":"race-event@0.0.0","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-Czz1adCZZjXgbkml6M9jhuzizeEMQbor4qqSj1847cKf/njCny7banGUeeE3JtXAVqJtCPRAq+7z0oXKCChi+A==","shasum":"a5d6d6d0879ae64aee2c990c6311b03ea21166d5","tarball":"http://registry-npm.ywwl.com/race-event/download/race-event-0.0.0.tgz","fileCount":10,"unpackedSize":13823,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC+kZeBfnUBd54PQbM0DtPR3WCx3Ocv7E8FU+z/q7rAtgIgMqfwELpZcAh+A0ghi+lRz2ijJcxlns0qCHHnsfhr9ng="}],"size":3950,"noattachment":false,"key":"/race-event/-/race-event-0.0.0.tgz"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"directories":{},"maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/race-event_0.0.0_1704437483800_0.14815894314372646"},"_hasShrinkwrap":false,"readme":"# race-event\n\n[![codecov](https://img.shields.io/codecov/c/github/achingbrain/race-event.svg?style=flat-square)](https://codecov.io/gh/achingbrain/race-event)\n[![CI](https://img.shields.io/github/actions/workflow/status/achingbrain/race-event/js-test-and-release.yml?branch=main\\&style=flat-square)](https://github.com/achingbrain/race-event/actions/workflows/js-test-and-release.yml?query=branch%3Amain)\n\n> Race an event against an AbortSignal\n\n# About\n\n<!--\n\n!IMPORTANT!\n\nEverything in this README between \"# About\" and \"# Install\" is automatically\ngenerated and will be overwritten the next time the doc generator is run.\n\nTo make changes to this section, please update the @packageDocumentation section\nof src/index.js or src/index.ts\n\nTo experiment with formatting, please run \"npm run docs\" from the root of this\nrepo and examine the changes made.\n\n-->\n\nRace an event against an AbortSignal, taking care to remove any event\nlisteners that were added.\n\n## Example - Getting started\n\n```TypeScript\nimport { raceEvent } from 'race-event'\n\nconst controller = new AbortController()\nconst emitter = new EventTarget()\n\nsetTimeout(() => {\n  controller.abort()\n}, 500)\n\nsetTimeout(() => {\n  // too late\n  emitter.dispatchEvent(new CustomEvent('event'))\n}, 1000)\n\n// throws an AbortError\nconst resolve = await raceEvent(emitter, 'event', controller.signal)\n```\n\n## Example - Aborting the promise with an error event\n\n```TypeScript\nimport { raceEvent } from 'race-event'\n\nconst emitter = new EventTarget()\n\nsetTimeout(() => {\n  emitter.dispatchEvent(new CustomEvent('failure', {\n    detail: new Error('Oh no!')\n  }))\n}, 1000)\n\n// throws 'Oh no!' error\nconst resolve = await raceEvent(emitter, 'success', AbortSignal.timeout(5000), {\n  errorEvent: 'failure'\n})\n```\n\n## Example - Customising the thrown AbortError\n\nThe error message and `.code` property of the thrown `AbortError` can be\nspecified by passing options:\n\n```TypeScript\nimport { raceEvent } from 'race-event'\n\nconst controller = new AbortController()\nconst emitter = new EventTarget()\n\nsetTimeout(() => {\n  controller.abort()\n}, 500)\n\n// throws a Error: Oh no!\nconst resolve = await raceEvent(emitter, 'event', controller.signal, {\n  errorMessage: 'Oh no!',\n  errorCode: 'ERR_OH_NO'\n})\n```\n\n## Example - Only resolving on specific events\n\nWhere multiple events with the same type are emitted, a `filter` function can\nbe passed to only resolve on one of them:\n\n```TypeScript\nimport { raceEvent } from 'race-event'\n\nconst controller = new AbortController()\nconst emitter = new EventTarget()\n\n// throws a Error: Oh no!\nconst resolve = await raceEvent(emitter, 'event', controller.signal, {\n  filter: (evt: Event) => {\n    return evt.detail.foo === 'bar'\n  }\n})\n```\n\n## Example - Terminating early by throwing from the filter\n\nYou can cause listening for the event to cease and all event listeners to be\nremoved by throwing from the filter:\n\n```TypeScript\nimport { raceEvent } from 'race-event'\n\nconst controller = new AbortController()\nconst emitter = new EventTarget()\n\n// throws Error: Cannot continue\nconst resolve = await raceEvent(emitter, 'event', controller.signal, {\n  filter: (evt) => {\n    if (...reasons) {\n      throw new Error('Cannot continue')\n    }\n\n    return true\n  }\n})\n```\n\n# Install\n\n```console\n$ npm i race-event\n```\n\n## Browser `<script>` tag\n\nLoading this module through a script tag will make it's exports available as `RaceEvent` in the global namespace.\n\n```html\n<script src=\"https://unpkg.com/race-event/dist/index.min.js\"></script>\n```\n\n# API Docs\n\n- <https://achingbrain.github.io/race-event>\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":1704437483980,"_cnpm_publish_time":1704437483980,"dist-tags":{"latest":"1.6.1"}}