Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

atomic

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atomic

makes a function atomic with timeout and abort signal

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
321
increased by0.31%
Maintainers
1
Weekly downloads
 
Created
Source

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<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

Keywords

FAQs

Package last updated on 20 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc