Skip to content

Commit

Permalink
code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jun 4, 2015
1 parent 3fadcf4 commit c8b315f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,9 @@ function $p(func) {

// Sequentially resolves dynamic promises returned by a factory;
function $sequence(t, factory) {
var idx = 0, result = [];

function loop(idx, result) {
function loop() {
var obj;
try {
obj = factory.call(t, idx, t); // get next promise;
Expand All @@ -681,11 +682,12 @@ function $sequence(t, factory) {
}
return obj.then(function (data) {
result.push(data);
return loop(++idx, result);
idx++;
return loop();
}, function (reason) {
return $p.reject(reason);
});
}

return loop(0, []);
return loop();
}

0 comments on commit c8b315f

Please sign in to comment.