sequencer - a deno 🦕 module for sequential promises
Deno promise sequencing.
Usage
To execute promises sequentially, simply add the functions returning the
promises to an array, and call await seq(array)
. Your promises will be
executed one sequentially! 🦕
import { seq } from "https://deno.land/x/sequencer/mod.ts";
const sleep = (t: number) => new Promise((res) => setTimeout(res, t));
let acc: Array<number> = [];
await seq([
() => sleep(10).then(() => acc.push(1)),
() => sleep(20).then(() => acc.push(2)),
() => sleep(1).then(() => acc.push(3)),
]);
console.log(seq); // > [ 1, 2, 3 ]
Test
deno test
Format code
deno fmt