async-lock
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -0,1 +1,5 @@ | ||
1.1.2 / 2018-02-28 | ||
================== | ||
* README.md improvements | ||
1.1.1 / 2018-02-14 | ||
@@ -2,0 +6,0 @@ ================== |
{ | ||
"name": "async-lock", | ||
"description": "Lock on asynchronous code", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Rogier Schouten", |
@@ -29,3 +29,3 @@ # async-lock | ||
```js | ||
redis.get('key', function(err, value){ | ||
redis.get('key', function(err, value) { | ||
redis.set('key', value * 2); | ||
@@ -47,8 +47,8 @@ }); | ||
```js | ||
lock.acquire('key', function(cb){ | ||
lock.acquire('key', function(cb) { | ||
// Concurrency safe | ||
redis.get('key', function(err, value){ | ||
redis.get('key', function(err, value) { | ||
redis.set('key', value * 2, cb); | ||
}); | ||
}, function(err, ret){ | ||
}, function(err, ret) { | ||
}); | ||
@@ -59,3 +59,3 @@ ``` | ||
``` | ||
```js | ||
var AsyncLock = require('async-lock'); | ||
@@ -70,6 +70,6 @@ var lock = new AsyncLock(); | ||
*/ | ||
lock.acquire(key, function(done){ | ||
lock.acquire(key, function(done) { | ||
// async work | ||
done(err, ret); | ||
}, function(err, ret){ | ||
}, function(err, ret) { | ||
// lock released | ||
@@ -79,5 +79,5 @@ }, opts); | ||
// Promise mode | ||
lock.acquire(key, function(){ | ||
lock.acquire(key, function() { | ||
// return value or promise | ||
}, opts).then(function(){ | ||
}, opts).then(function() { | ||
// lock released | ||
@@ -89,7 +89,7 @@ }); | ||
``` | ||
```js | ||
// Callback mode | ||
lock.acquire(key, function(done){ | ||
lock.acquire(key, function(done) { | ||
done(new Error('error')); | ||
}, function(err, ret){ | ||
}, function(err, ret) { | ||
console.log(err.message) // output: error | ||
@@ -99,5 +99,5 @@ }); | ||
// Promise mode | ||
lock.acquire(key, function(){ | ||
lock.acquire(key, function() { | ||
throw new Error('error'); | ||
}).catch(function(err){ | ||
}).catch(function(err) { | ||
console.log(err.message) // output: error | ||
@@ -109,3 +109,3 @@ }); | ||
``` | ||
```js | ||
lock.acquire([key1, key2], fn, cb); | ||
@@ -118,3 +118,3 @@ ``` | ||
``` | ||
```js | ||
var domain = require('domain'); | ||
@@ -124,6 +124,6 @@ var lock = new AsyncLock({domainReentrant : true}); | ||
var d = domain.create(); | ||
d.run(function(){ | ||
lock.acquire('key', function(){ | ||
d.run(function() { | ||
lock.acquire('key', function() { | ||
//Enter lock | ||
return lock.acquire('key', function(){ | ||
return lock.acquire('key', function() { | ||
//Enter same lock twice | ||
@@ -137,6 +137,6 @@ }); | ||
``` | ||
```js | ||
// Specify timeout | ||
var lock = new AsyncLock({timeout : 5000}); | ||
lock.acquire(key, fn, function(err, ret){ | ||
var lock = new AsyncLock({timeout: 5000}); | ||
lock.acquire(key, fn, function(err, ret) { | ||
// timed out error will be returned here if lock not acquired in given time | ||
@@ -146,4 +146,4 @@ }); | ||
// Set max pending tasks | ||
var lock = new AsyncLock({maxPending : 1000}); | ||
lock.acquire(key, fn, function(err, ret){ | ||
var lock = new AsyncLock({maxPending: 1000}); | ||
lock.acquire(key, fn, function(err, ret) { | ||
// Handle too much pending error | ||
@@ -156,4 +156,4 @@ }) | ||
// Use your own promise library instead of the global Promise variable | ||
var lock = new AsyncLock({Promise : require('bluebird')}); // Bluebird | ||
var lock = new AsyncLock({Promise : require('q')}); // Q | ||
var lock = new AsyncLock({Promise: require('bluebird')}); // Bluebird | ||
var lock = new AsyncLock({Promise: require('q')}); // Q | ||
@@ -160,0 +160,0 @@ // Add a task to the front of the queue waiting for a given lock |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14486