/** * Runs async work one call at a time, in the order it was asked for. * * A call made while another is in flight waits for it to finish, succeed or fail, before it starts. A failed * call is still reported to its own caller and does not stop the next one. */ export const oneAtATime = () => { let tail: Promise = Promise.resolve(); return (work: () => Promise): Promise => { const run = tail.then(work); tail = run.catch(() => undefined); return run; }; };