Socket
Socket
Sign inDemoInstall

deferred

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deferred - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

40

lib/ext/array/map.js

@@ -10,7 +10,18 @@ // Promise aware Array's map

, assertCallable = require('es5-ext/lib/Object/assert-callable')
, create = require('es5-ext/lib/Object/prototype/plain-create')
, deferred = require('../../deferred')
, isPromise = require('../../is-promise');
var proto = {
var Map = function (list, cb, thisArg, limit) {
this.list = list;
this.cb = cb;
this.context = thisArg;
this.limit = (limit >>> 0) || Infinity;
this.d = deferred();
this.result = new Array(list.length >>> 0)
this.held = [];
};
Map.prototype = {
waiting: 0,
iterate: function (value, index) {

@@ -56,3 +67,6 @@ if (!this.cb && isError(value)) {

--this.limit;
value.end(this.unhold.bind(this, index), this.d.resolve);
value.end(function (value) {
++this.limit;
this.unhold(index, value);
}.bind(this), this.d.resolve);
return true;

@@ -64,3 +78,3 @@ } else if (isError(value)) {

}
this.processResult(index, value);
this.unhold(index, value);
return true;

@@ -71,3 +85,2 @@ },

if (!this.d.promise._base.resolved) {
++this.limit;
if (this.held.length) {

@@ -95,18 +108,9 @@ this.held.shift()();

}
d = deferred();
every.call(this, (iterator = create.call(proto, {
d: d,
cb: cb,
held: [],
limit: (limit >>> 0) || Infinity,
list: this,
context: thisArg,
waiting: 0,
result: new Array(this.length >>> 0)
})).iterate, iterator);
every.call(this, (iterator = new Map(this, cb, thisArg, limit)).iterate,
iterator);
iterator.initialized = true;
if (!iterator.waiting) {
d.resolve(iterator.result);
iterator.d.resolve(iterator.result);
}
return d.promise;
return iterator.d.promise;
};
{
"name": "deferred",
"version": "0.5.2",
"version": "0.5.3",
"description": "Asynchronous control-flow with deferred and promises",

@@ -5,0 +5,0 @@ "keywords": [

'use strict';
var deferred = require('../../../lib/deferred')
var call = Function.prototype.call
, deferred = require('../../../lib/deferred')
, promise = require('../../../lib/promise');

@@ -177,2 +178,19 @@

}).end();
},
"Mixed (async/sync) queue": function (a) {
// Make sure that queued synchronous calls are released properly
var tbr = [], invoked = false;
t.call(arr, function (item, index) {
if (index > 2) {
return {};
} else {
var d = deferred();
tbr.push(d.resolve);
return d.promise;
}
}, null, 3).end(function () {
invoked = true;
});
tbr.map(call.bind(call));
a(invoked, true);
}

@@ -179,0 +197,0 @@ }

Sorry, the diff of this file is not supported yet

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