async-lock
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -0,1 +1,6 @@ | ||
1.1.4 / 2019-02-02 | ||
================== | ||
* Fix for #17 Promise.defer() resulting in console warnings | ||
* Fix for npm audit vulnerabilities (one remaining in dev deps) | ||
1.1.3 / 2018-06-08 | ||
@@ -2,0 +7,0 @@ ================== |
@@ -42,3 +42,7 @@ 'use strict'; | ||
// faux-deferred promise using new Promise() (as Promise.defer is deprecated) | ||
var deferredResolve = null; | ||
var deferredReject = null; | ||
var deferred = null; | ||
if (typeof (cb) !== 'function') { | ||
@@ -49,3 +53,6 @@ opts = cb; | ||
// will return a promise | ||
deferred = this._deferPromise(); | ||
deferred = new this.Promise((resolve, reject) => { | ||
deferredResolve = resolve; | ||
deferredReject = reject; | ||
}); | ||
} | ||
@@ -76,6 +83,6 @@ | ||
if (err) { | ||
deferred.reject(err); | ||
deferredReject(err); | ||
} | ||
else { | ||
deferred.resolve(ret); | ||
deferredResolve(ret); | ||
} | ||
@@ -166,3 +173,3 @@ } | ||
if (deferred) { | ||
return deferred.promise; | ||
return deferred; | ||
} | ||
@@ -209,17 +216,17 @@ }; | ||
else { | ||
var deferred = this._deferPromise(); | ||
// check for promise mode in case keys is empty array | ||
if (fnx.length === 1) { | ||
fnx(function (err, ret) { | ||
if (err) { | ||
deferred.reject(err); | ||
} | ||
else { | ||
deferred.resolve(ret); | ||
} | ||
}); | ||
} else { | ||
deferred.resolve(fnx()); | ||
} | ||
return deferred.promise; | ||
return new this.Promise((resolve, reject) => { | ||
// check for promise mode in case keys is empty array | ||
if (fnx.length === 1) { | ||
fnx(function (err, ret) { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(ret); | ||
} | ||
}); | ||
} else { | ||
resolve(fnx()); | ||
} | ||
}); | ||
} | ||
@@ -253,35 +260,3 @@ }; | ||
/** | ||
* 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": "1.1.3", | ||
"version": "1.1.4", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Rogier Schouten", |
@@ -159,3 +159,3 @@ # async-lock | ||
See [isse tracker](https://github.com/rogierschouten/async-lock/issues). | ||
See [issue tracker](https://github.com/rogierschouten/async-lock/issues). | ||
@@ -162,0 +162,0 @@ ## 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
13898
226