SkillAgentSearch skills...

Atomic

makes a function atomic with timeout and abort signal

Install / Use

/learn @stagas/Atomic
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<h1 align="center">atomic</h1> <p align="center"> makes a function atomic with timeout and abort signal </p> <p align="center"> <a href="#install"> 🔧 <strong>Install</strong></a> · <a href="#example"> 🧩 <strong>Example</strong></a> · <a href="#api"> 📜 <strong>API docs</strong></a> · <a href="https://github.com/stagas/atomic/releases"> 🔥 <strong>Releases</strong></a> · <a href="#contribute"> 💪🏼 <strong>Contribute</strong></a> · <a href="https://github.com/stagas/atomic/issues"> 🖐️ <strong>Help</strong></a> </p>

Install

$ npm i atomic

API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

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<any>): Promise<any> 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

View on GitHub
GitHub Stars14
CategoryDevelopment
Updated2y ago
Forks1

Languages

TypeScript

Security Score

65/100

Audited on Jan 19, 2024

No findings