function-loop
Advanced tools
Comparing version 1.0.1 to 1.0.2
17
index.js
@@ -7,2 +7,12 @@ module.exports = loop | ||
function once (cb) { | ||
var called = false | ||
return function (er) { | ||
if (called) | ||
return | ||
called = true | ||
return cb.call(this, er) | ||
} | ||
} | ||
function loop (self, arr, cb, onerr, i) { | ||
@@ -14,11 +24,12 @@ if (!i) | ||
while (i < arr.length && !running) { | ||
var onceNext = once(next) | ||
running = true | ||
var sync = true | ||
try { | ||
var ret = arr[i].call(self, next) | ||
var ret = arr[i].call(self, onceNext) | ||
} catch (er) { | ||
return onerr.call(self,er) | ||
return onerr.call(self, er) | ||
} | ||
if (ret && typeof ret.then === 'function') | ||
ret.then(next.bind(self, null), onerr.bind(self)) | ||
ret.then(onceNext.bind(self, null), onerr.bind(self)) | ||
i++ | ||
@@ -25,0 +36,0 @@ sync = false |
{ | ||
"name": "function-loop", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
15
test.js
@@ -108,1 +108,16 @@ var t = require('tap') | ||
}) | ||
t.test('cb and also promise resolve', function (t) { | ||
t.plan(1) | ||
loop(obj, [ | ||
function (cb) { | ||
return Promise.resolve('foo').then(function () { | ||
cb() | ||
}) | ||
} | ||
], function () { | ||
t.pass('finished one time') | ||
}, function (er) { | ||
throw er | ||
}) | ||
}) |
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
5073
254395
161