import { queue } from "https://deno.land/x/ayonli_jsext@v0.9.72/index.ts";
Processes data sequentially by the given handler
function and prevents
concurrency conflicts, it returns a Queue instance that we can push
data into.
Examples
Example 1
Example 1
import queue from "@ayonli/jsext/queue";
const list: string[] = [];
const q = queue(async (str: string) => {
await Promise.resolve(null);
list.push(str);
});
q.onError(err => {
console.error(err);
})
await q.push("foo");
await q.push("foo");
console.log(list.length);
q.close();
// output:
// 2
Parameters
handler: (data: T) => Promise<void>
The maximum capacity of the underlying channel, once reached, the push operation will block until there is new space available. By default, this option is not set and use a non-buffered channel instead.