function createQueue() {
let tail = Promise.resolve();
return {
add(task) {
const result = tail.then(() => task());
tail = result.catch(() => {}); // keep queue running on error
return result;
},
};
}
// Usage
const q = createQueue();
q.add(() => fetch('/api/step1').then((r) => r.json())).then(console.log);
q.add(() => fetch('/api/step2').then((r) => r.json())).then(console.log);
// step2 only starts after step1 finishes
Create a free account and build your private vault. Share publicly whenever you want.