ato
atomic
npm i atomic
ato

atomic

makes a function atomic with timeout and abort signal

by stagas

1.0.0 (see all)License:MITTypeScript:Built-In
npm i atomic
Readme

atomic

makes a function atomic with timeout and abort signal

🔧 Install · 🧩 Example · 📜 API docs · 🔥 Releases · 💪🏼 Contribute · 🖐️ Help


Install

$ npm i atomic

API

Table of Contents

atomic

src/index.ts:33-78

Makes a function atomic.

const fn = atomic(signal => async () => {
  // some long async operation

  // if we've been aborted during the long
  // async process above, we wouldn't want
  // to continue so lets return here
  if (signal.aborted) return

  // do things here if we didn't abort
}, 500) // timeout at 500ms (don't pass anything for no timeout)
fn()
fn()
fn()
await fn() // this will run after the above have settled

Parameters

  • signalClosure function (signal: AbortSignal): function (...args: Array\): Promise\ A function that receives the signal object from an AbortController and returns the function to become atomic.
  • maxTimeMs number? Time in milliseconds to timeout the operation. Will also signal abort.

Returns any An atomic function

Contribute

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2022 stagas

Downloads/wk

27

GitHub Stars

10

LAST COMMIT

4mos ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
1.0.0
latest
4mos ago
No alternatives found
No tutorials found
Add a tutorial