Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

areq

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

areq - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

.travis.yml

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": {}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc