{
"data": [
{
"id": 1
}
],
"anotherData": [
{
"id": 0
}
]
}
let func0 = function () {
return new Promise(resolve=> {
setTimeout(()=>resolve(33), 1000);
});
};
let func1 = function (x) {
return new Promise(resolve=> {
setTimeout((x)=>resolve(x + 1), 1000);
});
};
let func2 = function (x) {
return new Promise(resolve=> {
setTimeout((x)=>resolve(x + 1), 1000);
});
};
let func3 = function (x) {
return new Promise(resolve=> {
setTimeout((x)=>{
resolve(x + 1);
console.log(x);
}, 1000);
});
};
const arr = [func0, func1, func2, func3];
const fn = arr =>
arr.reduce((acc, fn) => acc.then(fn), Promise.resolve());
console.log(fn(arr));