async-lock
Advanced tools
Comparing version 0.3.9 to 0.3.10
@@ -0,1 +1,5 @@ | ||
0.3.10 / 2017-06-27 | ||
================== | ||
* Remove dependencies on Q-specific nodify(), try(), and defer() methods so that you can inject e.g. standard ES6 promises using `new AsyncLock({ Promise: Promise })` | ||
0.3.9 / 2016-11-30 | ||
@@ -2,0 +6,0 @@ ================== |
@@ -48,3 +48,3 @@ 'use strict'; | ||
// will return a promise | ||
deferred = this.Promise.defer(); | ||
deferred = this._deferPromise(); | ||
} | ||
@@ -118,8 +118,10 @@ | ||
// Promise mode | ||
self.Promise.try(function () { | ||
self._promiseTry(function () { | ||
return fn(); | ||
}) | ||
.nodeify(function (err, ret) { | ||
done(locked, err, ret); | ||
}); | ||
.then(function(ret){ | ||
done(locked, undefined, ret); | ||
}, function(error){ | ||
done(locked, error); | ||
}); | ||
} | ||
@@ -200,3 +202,3 @@ }; | ||
else { | ||
var deferred = this.Promise.defer(); | ||
var deferred = this._deferPromise(); | ||
fnx(function (err, ret) { | ||
@@ -228,3 +230,46 @@ if (err) { | ||
/** | ||
* Promise.try() implementation to become independent of Q-specific methods | ||
*/ | ||
AsyncLock.prototype._promiseTry = function(fn) { | ||
try { | ||
return this.Promise.resolve(fn()); | ||
} catch (e) { | ||
return this.Promise.reject(e); | ||
} | ||
}; | ||
/** | ||
* Promise.defer() implementation to become independent of Q-specific methods | ||
*/ | ||
AsyncLock.prototype._deferPromise = function() { | ||
if (typeof this.Promise.defer === "function") { | ||
// note that Q does not have a constructor with reject/resolve functions so we have no option but use its defer() method | ||
return this.Promise.defer(); | ||
} else { | ||
// for promise implementations that don't have a defer() method we create one ourselves | ||
var result = { | ||
reject: function(err) { | ||
// some promise libraries e.g. Q take some time setting the reject property while others do it synchronously | ||
return Promise.resolve().then(function() { | ||
result.reject(err); | ||
}); | ||
}, | ||
resolve: function(ret) { | ||
// some promise libraries e.g. Q take some time setting the reject property while others do it synchronously | ||
return Promise.resolve().then(function() { | ||
result.resolve(ret); | ||
}); | ||
}, | ||
promise: undefined | ||
}; | ||
result.promise = new this.Promise(function(resolve, reject) { | ||
result.reject = reject; | ||
result.resolve = resolve; | ||
}); | ||
return result; | ||
} | ||
}; | ||
module.exports = AsyncLock; | ||
{ | ||
"name": "async-lock", | ||
"description": "Lock on asynchronous code", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"author": { | ||
@@ -35,9 +35,9 @@ "name": "Rogier Schouten", | ||
"dependencies": { | ||
"q": "~1.4.1" | ||
"q": "~1.5.0" | ||
}, | ||
"devDependencies": { | ||
"bluebird": "~3.4.6", | ||
"bluebird": "~3.5.0", | ||
"grunt": "^1.0.1", | ||
"grunt-cli": "~1.2.0", | ||
"grunt-contrib-clean": "~1.0.0", | ||
"grunt-contrib-clean": "~1.1.0", | ||
"grunt-contrib-jshint": "~1.1.0", | ||
@@ -50,4 +50,4 @@ "grunt-contrib-watch": "~1.0.0", | ||
"mocha": "^3.2.0", | ||
"should": "~11.1.1" | ||
"should": "~11.2.1" | ||
} | ||
} |
@@ -135,4 +135,5 @@ # async-lock | ||
// Use your own promise | ||
var lock = new AsyncLock({Promise : require('bluebird')}); | ||
// Use your own promise library instead of Q | ||
var lock = new AsyncLock({Promise : require('bluebird')}); // Bluebird | ||
var lock = new AsyncLock({Promise : Promise}); // Node/ES6 promise | ||
``` | ||
@@ -144,4 +145,8 @@ | ||
## Issues | ||
See [isse tracker](https://github.com/rogierschouten/async-lock/issues). | ||
## License | ||
MIT, see [LICENSE](./LICENSE) |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
151
0
13408
8
241