UNPKG

todomvc

Version:

> Helping you select an MV\* framework

49 lines (40 loc) 1.24 kB
/** @license MIT License (c) copyright 2011-2013 original author or authors */ /** * sequence.js * * Run a set of task functions in sequence. All tasks will * receive the same args. * * @author Brian Cavalier * @author John Hann */ (function(define) { define(function(require) { var when, slice; when = require('./when'); slice = Array.prototype.slice; /** * Run array of tasks in sequence with no overlap * @param tasks {Array|Promise} array or promiseForArray of task functions * @param [args] {*} arguments to be passed to all tasks * @return {Promise} promise for an array containing * the result of each task in the array position corresponding * to position of the task in the tasks array */ return function sequence(tasks /*, args... */) { var results = []; return when.all(slice.call(arguments, 1)).then(function(args) { return when.reduce(tasks, function(results, task) { return when(task.apply(null, args), addResult); }, results); }); function addResult(result) { results.push(result); return results; } }; }); })( typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); } // Boilerplate for AMD and Node );