Skip to content

Commit

Permalink
code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Apr 26, 2015
1 parent 9d78844 commit 065c6ee
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,20 @@ function $p(func) {
function $sequence(t, factory) {

function loop(factory, idx, result) {
var e;
var obj;
try {
e = factory(t, idx); // get next promise;
obj = factory(t, idx); // get next promise;
} catch (e) {
return $p.reject(e.message || e);
}
if (!e) {
if (!obj) {
// no more promises left in the sequence;
return $p.resolve(result);
}
if (typeof(e.then) !== 'function') {
if (typeof(obj.then) !== 'function') {
return $p.reject("Promise factory returned invalid result for index " + idx);
}
return e.then(function (data) {
return obj.then(function (data) {
result.push(data);
return loop(factory, ++idx, result);
}, function (reason) {
Expand Down

0 comments on commit 065c6ee

Please sign in to comment.