Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/esm/workerd/index.js>queue

A JavaScript extension package for building strong and modern applications.
Latest
function queue
Re-export
import { queue } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/workerd/index.js";

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

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

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.

optional
bufferSize = [UNSUPPORTED]