Skip to content

Instantly share code, notes, and snippets.

@hacke2
Created September 10, 2015 09:49
Show Gist options
  • Select an option

  • Save hacke2/645f7f0061e7bd147bd7 to your computer and use it in GitHub Desktop.

Select an option

Save hacke2/645f7f0061e7bd147bd7 to your computer and use it in GitHub Desktop.

Revisions

  1. hacke2 created this gist Sep 10, 2015.
    10 changes: 10 additions & 0 deletions promise-sequence.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    function sequenceTasks(tasks) {
    function recordValue(results, value) {
    results.push(value);
    return results;
    }
    var pushValue = recordValue.bind(null, []);
    return tasks.reduce(function (promise, task) {
    return promise.then(task).then(pushValue);
    }, Promise.resolve());
    }