Module exposing: AsyncQueue, PriorityAsyncQueue, SharedPriorityTarget
// Source: https://github.com/toeverything/AFFiNE | License: MIT | Copyright 2022-present TOEVERYTHING PTE. LTD. and its affiliates
// Provided via justclaw.it.com; keep this notice with the code.
export class AsyncQueue<T> {
private _queue: T[];
private _resolveUpdate: (() => void) | null = null;
private _waitForUpdate: Promise<void> | null = null;
get length() {
return this._queue.length;
}
constructor(init: T[] = []) {
this._queue = init;
}
clear() {
this._queue = [];
}
find(predicate: (update: T) => boolean) {
return this._queue.find(predicate);
}
async next(
abort?: AbortSignal,
dequeue: (arr: T[]) => T | undefined = a => a.shift()
): Promise<T> {
const update = dequeue(this._queue);
if (update) {
return update;
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key