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

Atomic operations

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
497
decreased by-17.03%
Maintainers
1
Weekly downloads
 
Created
Source

atomic

Atomic operations

Introduction

atomic lets you perform atomic operations based on keys. Additional tasks that try to access the same key get queued up and executed when the previous task calls done() to indicate it has finished its operation. It's useful when you want to perform a multiple I/O calls on databases and don't want anything else messing with your values in-between calls.

Installation

npm install atomic

Example

var atomic = require('atomic')()

var o = {} // here's our db

for (var i = 1; i <= 100; i++) {
  // create an atomic operation on key 'foo'
  atomic('foo', function (done, key, i) {
    setTimeout(function () {
      o[key] = i // store i in o[key]
      done() // done with this task, "unlock" key
             // and move to the next task in queue
    }, Math.floor(Math.random() * 50)) // sometime in the future
  }, i) // pass i to the arguments (closure)
}

atomic('foo', function (done, key) {
  console.log(o[key])
  done()
})

Usage

atomic(key, callback(done, key, arg1, arg2, ...) [, arg1, arg2, ...])

This creates an atomic operation on key. The callback is called when the key is free (other tasks have finished working on it) and you must call done() when you're finished your operations. For convenience, the key name and extra arguments are passed to the callback for your function to use.

FAQs

Package last updated on 11 Oct 2011

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