Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/yxz/async/queue.ts>AsyncQueue

Deno Standard Extensions
Latest
class AsyncQueue
extends EventTarget
Deprecated
Deprecated

use npm:p-queue instead

import { AsyncQueue } from "https://deno.land/x/yxz@0.32.0/async/queue.ts";

Promise queue with concurrency control

Type Parameters

optional
QueueType extends Queue<RunFunction, EnqueueOptionsType> = PriorityQueue
optional
EnqueueOptionsType extends QueueAddOptions = QueueAddOptions

Properties

concurrency: number
readonly
isPaused: boolean

Whether the queue is currently paused.

readonly
pending: number

Number of running items (no longer in the queue).

readonly
size: number

Size of the queue, the number of queued items waiting to run.

timeout: number | undefined

Set the timeout for future operations.

Methods

private
emit<T>(type: string, detail?: T)
add<TaskResultType>(fn: Task<TaskResultType>, options?: Partial<EnqueueOptionsType>): Promise<TaskResultType>

Adds a sync or async task to the queue. Always returns a promise.

addAll<TaskResultsType>(functions: ReadonlyArray<Task<TaskResultsType>>, options?: EnqueueOptionsType): Promise<TaskResultsType[]>

Same as .add(), but accepts an array of sync or async functions.

clear(): void

Clear the queue.

on(...args: Parameters<this.addEventListener>)
onEmpty(): Promise<void>

Can be called multiple times. Useful if you for example add additional items at a later time

onIdle(): Promise<void>

The difference with .onEmpty is that .onIdle guarantees that all work from the queue has finished. .onEmpty merely signals that the queue is empty, but it could mean that some promises haven't completed yet

onSizeLessThan(limit: number): Promise<void>
pause(): void

Put queue execution on hold.

sizeBy(options: Readonly<Partial<EnqueueOptionsType>>): number

Size of the queue, filtered by the given options.

For example, this can be used to find the number of items remaining in the queue with a specific priority level.

start(): this

Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via options.autoStart = false or by .pause() method.)