Example 3-13. Build sequential chain using recursion
// Replaces sequence in previous example with a recursive implementation
function sequence(array, callback) {
function chain(array, index) {
if (index == array.length) return Promise.resolve();
return Promise.resolve(callback(array[index])).then(function () {
return chain(array, index + 1);
});
}
return chain(array, 0);
}
// Console output is identical to Example 3-12
// Requested info for sku-1
// Info for sku-1
// Requested info for sku-2
// Info for sku-2
// Requested info for sku-3
// Info for sku-3