This repository contains a library that transforms your function calls into an `atomic` version of it given a lock name.
Installation
npm install atomicfn --save
Usage
atomic
is just a function that takes your function plus some other parameters and returns another function that is the atomic version of it.
As long as your function implements the callback methodology
Example Usage
The example below is a taking a setting the global var
val
atomically regardless of the async nature of it. The non atomic version will probably set the val to0
at the end. The atomic version below sets the intended value10
at the end.
// Require the atomic libraryconst atomic = atomic; const limit = 10var val = 0; // Your functionconst setVal = { ;} /* * This is how you make your function atomic * Parameters: * yourFunction:(required) * theLockName(required), * theTimeout(optional default=60000) * theCheckInterval(optional default=50) */const setValAtomic = ; for var i = 1; i <= limit; i++
Tests
npm test
Release History
- 0.0.1 Initial release
- 0.0.2 Fixed a bug related to fat arrow usage
- 0.0.3 Added support for node < 6 (es5)
- 0.0.4 Added support for Concurency now we can specfy a concurency value as parameter