Make a dynamic chain of promises
Use
arr.reduce((c, d) => c.then(() => fn(d)), Promise.resolve()).catch(error);
to convert
const arr = [d1, d2, d3, ..., dn];
const fn = async (d) => { /* returns a promise */ };
into
Promise.resolve().then(() => fn(d1)).then(() => fn(d2)).then(() => fn(d3))...then(() => fn(dn)).catch(error)