Comparing version 0.0.3 to 0.0.4
62
index.js
var EventEmitter = require('events'); | ||
function Areq(emitter, areqTimeout) { | ||
if (!emitter instanceof EventEmitter) | ||
if (! (emitter instanceof EventEmitter)) | ||
throw new TypeError('Input emitter should be an EventEmitter.'); | ||
@@ -12,20 +12,11 @@ | ||
Areq.prototype.resolve = function (evt, value) { | ||
var rec = this.getRecord(evt), | ||
deferred = rec ? rec.deferred : null; | ||
if (deferred && deferred.promise.isPending()) | ||
deferred.resolve(value); | ||
this.deregister(evt); | ||
Areq.prototype.getRecord = function (evt) { | ||
throwIfEvtNotString(evt); | ||
return this._pendings[evt]; | ||
}; | ||
Areq.prototype.reject = function (evt, err) { | ||
var rec = this.getRecord(evt), | ||
deferred = rec ? rec.deferred : null; | ||
if (deferred && deferred.promise.isPending()) | ||
deferred.reject(err); | ||
this.deregister(evt); | ||
Areq.prototype.isEventPending = function (evt) { | ||
throwIfEvtNotString(evt); | ||
return !!this._pendings[evt]; | ||
}; | ||
@@ -38,11 +29,11 @@ | ||
if (typeof evt !== 'string') | ||
throw new TypeError('evt should be a string.'); | ||
if (typeof listener !== 'function') | ||
throw new TypeError('listener should be a function.'); | ||
if (this.getRecord(evt)) { // someone waiting same event | ||
if (this.getRecord(evt)) { // someone waiting same event, throw if evt is not a string | ||
registered = false; | ||
} else { | ||
if (!deferred.hasOwnProperty('promise')) | ||
throw new TypeError('deferred should be a deferred object of Promise.'); | ||
deferred.promise.timeout(areqTimeout).fail(function(err) { | ||
@@ -66,5 +57,2 @@ deferred.reject(err); | ||
Areq.prototype.deregister = function (evt) { | ||
if (typeof evt !== 'string') | ||
throw new TypeError('evt should be a string.'); | ||
var rec = this.getRecord(evt), | ||
@@ -87,13 +75,27 @@ emitter = this._emitter; | ||
Areq.prototype.getRecord = function (evt) { | ||
return this._pendings[evt]; | ||
Areq.prototype.resolve = function (evt, value) { | ||
var rec = this.getRecord(evt), | ||
deferred = rec ? rec.deferred : null; | ||
if (deferred && deferred.promise.isPending()) | ||
deferred.resolve(value); | ||
this.deregister(evt); | ||
}; | ||
Areq.prototype.isEventPending = function (evt) { | ||
return !!this._pendings[evt]; | ||
Areq.prototype.reject = function (evt, err) { | ||
var rec = this.getRecord(evt), | ||
deferred = rec ? rec.deferred : null; | ||
if (deferred && deferred.promise.isPending()) | ||
deferred.reject(err); | ||
this.deregister(evt); | ||
}; | ||
/*************************************************************************************************/ | ||
/*** Module Exports ***/ | ||
/*************************************************************************************************/ | ||
function throwIfEvtNotString (evt) { | ||
if (typeof evt !== 'string') | ||
throw new TypeError('evt should be a string.'); | ||
} | ||
module.exports = Areq; |
{ | ||
"name": "areq", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "An asynchronous request controller", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "make test-all" | ||
}, | ||
@@ -18,3 +18,9 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/zigbeer/areq#readme" | ||
"homepage": "https://github.com/zigbeer/areq#readme", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^2.5.3", | ||
"q": "^1.4.1" | ||
}, | ||
"dependencies": {} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
24435
8
359
1
3
1