/* * promiseSerial resolves Promises sequentially. * Puts results into an array and get it from then() * * @example * const urls = ['/url1', '/url2', '/url3'] * const funcs = urls.map(url => () => $.ajax(url)) * * promiseSerial(funcs) * .then(console.log.bind(console)) * .catch(console.error.bind(console)) */ const chainPromise = funcs => funcs.reduce((promise, func) => // can pass result to func if prev result is needed promise.then(result => func().then(Array.prototype.concat.bind(result))), Promise.resolve([]));