Fix bin/publish: copy docs.dist from project root

Fix bin/publish: use correct .env path for rspade_system
Fix bin/publish script: prevent grep exit code 1 from terminating script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-10-21 02:08:33 +00:00
commit f6fac6c4bc
79758 changed files with 10547827 additions and 0 deletions

101
vendor/spatie/ignition/node_modules/p-queue/dist/index.d.ts generated vendored Executable file
View File

@@ -0,0 +1,101 @@
import EventEmitter = require('eventemitter3');
import { Queue, RunFunction } from './queue';
import PriorityQueue from './priority-queue';
import { QueueAddOptions, DefaultAddOptions, Options } from './options';
declare type Task<TaskResultType> = (() => PromiseLike<TaskResultType>) | (() => TaskResultType);
/**
Promise queue with concurrency control.
*/
export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsType> = PriorityQueue, EnqueueOptionsType extends QueueAddOptions = DefaultAddOptions> extends EventEmitter<'active' | 'idle' | 'add' | 'next'> {
private readonly _carryoverConcurrencyCount;
private readonly _isIntervalIgnored;
private _intervalCount;
private readonly _intervalCap;
private readonly _interval;
private _intervalEnd;
private _intervalId?;
private _timeoutId?;
private _queue;
private readonly _queueClass;
private _pendingCount;
private _concurrency;
private _isPaused;
private _resolveEmpty;
private _resolveIdle;
private _timeout?;
private readonly _throwOnTimeout;
constructor(options?: Options<QueueType, EnqueueOptionsType>);
private get _doesIntervalAllowAnother();
private get _doesConcurrentAllowAnother();
private _next;
private _resolvePromises;
private _onResumeInterval;
private _isIntervalPaused;
private _tryToStartAnother;
private _initializeIntervalIfNeeded;
private _onInterval;
/**
Executes all queued functions until it reaches the limit.
*/
private _processQueue;
get concurrency(): number;
set concurrency(newConcurrency: number);
/**
Adds a sync or async task to the queue. Always returns a promise.
*/
add<TaskResultType>(fn: Task<TaskResultType>, options?: Partial<EnqueueOptionsType>): Promise<TaskResultType>;
/**
Same as `.add()`, but accepts an array of sync or async functions.
@returns A promise that resolves when all functions are resolved.
*/
addAll<TaskResultsType>(functions: ReadonlyArray<Task<TaskResultsType>>, options?: EnqueueOptionsType): Promise<TaskResultsType[]>;
/**
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.)
*/
start(): this;
/**
Put queue execution on hold.
*/
pause(): void;
/**
Clear the queue.
*/
clear(): void;
/**
Can be called multiple times. Useful if you for example add additional items at a later time.
@returns A promise that settles when the queue becomes empty.
*/
onEmpty(): 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.
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
*/
onIdle(): Promise<void>;
/**
Size of the queue.
*/
get size(): 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.
*/
sizeBy(options: Readonly<Partial<EnqueueOptionsType>>): number;
/**
Number of pending promises.
*/
get pending(): number;
/**
Whether the queue is currently paused.
*/
get isPaused(): boolean;
get timeout(): number | undefined;
/**
Set the timeout for future operations.
*/
set timeout(milliseconds: number | undefined);
}
export { Queue, QueueAddOptions, DefaultAddOptions, Options };

279
vendor/spatie/ignition/node_modules/p-queue/dist/index.js generated vendored Executable file
View File

@@ -0,0 +1,279 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const EventEmitter = require("eventemitter3");
const p_timeout_1 = require("p-timeout");
const priority_queue_1 = require("./priority-queue");
// eslint-disable-next-line @typescript-eslint/no-empty-function
const empty = () => { };
const timeoutError = new p_timeout_1.TimeoutError();
/**
Promise queue with concurrency control.
*/
class PQueue extends EventEmitter {
constructor(options) {
var _a, _b, _c, _d;
super();
this._intervalCount = 0;
this._intervalEnd = 0;
this._pendingCount = 0;
this._resolveEmpty = empty;
this._resolveIdle = empty;
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
options = Object.assign({ carryoverConcurrencyCount: false, intervalCap: Infinity, interval: 0, concurrency: Infinity, autoStart: true, queueClass: priority_queue_1.default }, options);
if (!(typeof options.intervalCap === 'number' && options.intervalCap >= 1)) {
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(_b = (_a = options.intervalCap) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''}\` (${typeof options.intervalCap})`);
}
if (options.interval === undefined || !(Number.isFinite(options.interval) && options.interval >= 0)) {
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(_d = (_c = options.interval) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : ''}\` (${typeof options.interval})`);
}
this._carryoverConcurrencyCount = options.carryoverConcurrencyCount;
this._isIntervalIgnored = options.intervalCap === Infinity || options.interval === 0;
this._intervalCap = options.intervalCap;
this._interval = options.interval;
this._queue = new options.queueClass();
this._queueClass = options.queueClass;
this.concurrency = options.concurrency;
this._timeout = options.timeout;
this._throwOnTimeout = options.throwOnTimeout === true;
this._isPaused = options.autoStart === false;
}
get _doesIntervalAllowAnother() {
return this._isIntervalIgnored || this._intervalCount < this._intervalCap;
}
get _doesConcurrentAllowAnother() {
return this._pendingCount < this._concurrency;
}
_next() {
this._pendingCount--;
this._tryToStartAnother();
this.emit('next');
}
_resolvePromises() {
this._resolveEmpty();
this._resolveEmpty = empty;
if (this._pendingCount === 0) {
this._resolveIdle();
this._resolveIdle = empty;
this.emit('idle');
}
}
_onResumeInterval() {
this._onInterval();
this._initializeIntervalIfNeeded();
this._timeoutId = undefined;
}
_isIntervalPaused() {
const now = Date.now();
if (this._intervalId === undefined) {
const delay = this._intervalEnd - now;
if (delay < 0) {
// Act as the interval was done
// We don't need to resume it here because it will be resumed on line 160
this._intervalCount = (this._carryoverConcurrencyCount) ? this._pendingCount : 0;
}
else {
// Act as the interval is pending
if (this._timeoutId === undefined) {
this._timeoutId = setTimeout(() => {
this._onResumeInterval();
}, delay);
}
return true;
}
}
return false;
}
_tryToStartAnother() {
if (this._queue.size === 0) {
// We can clear the interval ("pause")
// Because we can redo it later ("resume")
if (this._intervalId) {
clearInterval(this._intervalId);
}
this._intervalId = undefined;
this._resolvePromises();
return false;
}
if (!this._isPaused) {
const canInitializeInterval = !this._isIntervalPaused();
if (this._doesIntervalAllowAnother && this._doesConcurrentAllowAnother) {
const job = this._queue.dequeue();
if (!job) {
return false;
}
this.emit('active');
job();
if (canInitializeInterval) {
this._initializeIntervalIfNeeded();
}
return true;
}
}
return false;
}
_initializeIntervalIfNeeded() {
if (this._isIntervalIgnored || this._intervalId !== undefined) {
return;
}
this._intervalId = setInterval(() => {
this._onInterval();
}, this._interval);
this._intervalEnd = Date.now() + this._interval;
}
_onInterval() {
if (this._intervalCount === 0 && this._pendingCount === 0 && this._intervalId) {
clearInterval(this._intervalId);
this._intervalId = undefined;
}
this._intervalCount = this._carryoverConcurrencyCount ? this._pendingCount : 0;
this._processQueue();
}
/**
Executes all queued functions until it reaches the limit.
*/
_processQueue() {
// eslint-disable-next-line no-empty
while (this._tryToStartAnother()) { }
}
get concurrency() {
return this._concurrency;
}
set concurrency(newConcurrency) {
if (!(typeof newConcurrency === 'number' && newConcurrency >= 1)) {
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
}
this._concurrency = newConcurrency;
this._processQueue();
}
/**
Adds a sync or async task to the queue. Always returns a promise.
*/
async add(fn, options = {}) {
return new Promise((resolve, reject) => {
const run = async () => {
this._pendingCount++;
this._intervalCount++;
try {
const operation = (this._timeout === undefined && options.timeout === undefined) ? fn() : p_timeout_1.default(Promise.resolve(fn()), (options.timeout === undefined ? this._timeout : options.timeout), () => {
if (options.throwOnTimeout === undefined ? this._throwOnTimeout : options.throwOnTimeout) {
reject(timeoutError);
}
return undefined;
});
resolve(await operation);
}
catch (error) {
reject(error);
}
this._next();
};
this._queue.enqueue(run, options);
this._tryToStartAnother();
this.emit('add');
});
}
/**
Same as `.add()`, but accepts an array of sync or async functions.
@returns A promise that resolves when all functions are resolved.
*/
async addAll(functions, options) {
return Promise.all(functions.map(async (function_) => this.add(function_, options)));
}
/**
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.)
*/
start() {
if (!this._isPaused) {
return this;
}
this._isPaused = false;
this._processQueue();
return this;
}
/**
Put queue execution on hold.
*/
pause() {
this._isPaused = true;
}
/**
Clear the queue.
*/
clear() {
this._queue = new this._queueClass();
}
/**
Can be called multiple times. Useful if you for example add additional items at a later time.
@returns A promise that settles when the queue becomes empty.
*/
async onEmpty() {
// Instantly resolve if the queue is empty
if (this._queue.size === 0) {
return;
}
return new Promise(resolve => {
const existingResolve = this._resolveEmpty;
this._resolveEmpty = () => {
existingResolve();
resolve();
};
});
}
/**
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.
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
*/
async onIdle() {
// Instantly resolve if none pending and if nothing else is queued
if (this._pendingCount === 0 && this._queue.size === 0) {
return;
}
return new Promise(resolve => {
const existingResolve = this._resolveIdle;
this._resolveIdle = () => {
existingResolve();
resolve();
};
});
}
/**
Size of the queue.
*/
get size() {
return this._queue.size;
}
/**
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.
*/
sizeBy(options) {
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
return this._queue.filter(options).length;
}
/**
Number of pending promises.
*/
get pending() {
return this._pendingCount;
}
/**
Whether the queue is currently paused.
*/
get isPaused() {
return this._isPaused;
}
get timeout() {
return this._timeout;
}
/**
Set the timeout for future operations.
*/
set timeout(milliseconds) {
this._timeout = milliseconds;
}
}
exports.default = PQueue;

View File

@@ -0,0 +1 @@
export default function lowerBound<T>(array: readonly T[], value: T, comparator: (a: T, b: T) => number): number;

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound
// Used to compute insertion index to keep queue sorted after insertion
function lowerBound(array, value, comparator) {
let first = 0;
let count = array.length;
while (count > 0) {
const step = (count / 2) | 0;
let it = first + step;
if (comparator(array[it], value) <= 0) {
first = ++it;
count -= step + 1;
}
else {
count = step;
}
}
return first;
}
exports.default = lowerBound;

View File

@@ -0,0 +1,64 @@
import { Queue, RunFunction } from './queue';
export interface QueueAddOptions {
readonly [key: string]: unknown;
}
export interface Options<QueueType extends Queue<RunFunction, QueueOptions>, QueueOptions extends QueueAddOptions> {
/**
Concurrency limit.
Minimum: `1`.
@default Infinity
*/
readonly concurrency?: number;
/**
Whether queue tasks within concurrency limit, are auto-executed as soon as they're added.
@default true
*/
readonly autoStart?: boolean;
/**
Class with a `enqueue` and `dequeue` method, and a `size` getter. See the [Custom QueueClass](https://github.com/sindresorhus/p-queue#custom-queueclass) section.
*/
readonly queueClass?: new () => QueueType;
/**
The max number of runs in the given interval of time.
Minimum: `1`.
@default Infinity
*/
readonly intervalCap?: number;
/**
The length of time in milliseconds before the interval count resets. Must be finite.
Minimum: `0`.
@default 0
*/
readonly interval?: number;
/**
Whether the task must finish in the given interval or will be carried over into the next interval count.
@default false
*/
readonly carryoverConcurrencyCount?: boolean;
/**
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
*/
timeout?: number;
/**
Whether or not a timeout is considered an exception.
@default false
*/
throwOnTimeout?: boolean;
}
export interface DefaultAddOptions extends QueueAddOptions {
/**
Priority of operation. Operations with greater priority will be scheduled first.
@default 0
*/
readonly priority?: number;
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,12 @@
import { Queue, RunFunction } from './queue';
import { QueueAddOptions } from './options';
export interface PriorityQueueOptions extends QueueAddOptions {
priority?: number;
}
export default class PriorityQueue implements Queue<RunFunction, PriorityQueueOptions> {
private readonly _queue;
enqueue(run: RunFunction, options?: Partial<PriorityQueueOptions>): void;
dequeue(): RunFunction | undefined;
filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[];
get size(): number;
}

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lower_bound_1 = require("./lower-bound");
class PriorityQueue {
constructor() {
this._queue = [];
}
enqueue(run, options) {
options = Object.assign({ priority: 0 }, options);
const element = {
priority: options.priority,
run
};
if (this.size && this._queue[this.size - 1].priority >= options.priority) {
this._queue.push(element);
return;
}
const index = lower_bound_1.default(this._queue, element, (a, b) => b.priority - a.priority);
this._queue.splice(index, 0, element);
}
dequeue() {
const item = this._queue.shift();
return item === null || item === void 0 ? void 0 : item.run;
}
filter(options) {
return this._queue.filter((element) => element.priority === options.priority).map((element) => element.run);
}
get size() {
return this._queue.length;
}
}
exports.default = PriorityQueue;

View File

@@ -0,0 +1,7 @@
export declare type RunFunction = () => Promise<unknown>;
export interface Queue<Element, Options> {
size: number;
filter: (options: Partial<Options>) => Element[];
dequeue: () => Element | undefined;
enqueue: (run: Element, options?: Partial<Options>) => void;
}

2
vendor/spatie/ignition/node_modules/p-queue/dist/queue.js generated vendored Executable file
View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

9
vendor/spatie/ignition/node_modules/p-queue/license generated vendored Executable file
View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

400
vendor/spatie/ignition/node_modules/p-queue/readme.md generated vendored Executable file
View File

@@ -0,0 +1,400 @@
# p-queue [![Build Status](https://travis-ci.com/sindresorhus/p-queue.svg?branch=master)](https://travis-ci.com/github/sindresorhus/p-queue) [![codecov](https://codecov.io/gh/sindresorhus/p-queue/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/p-queue)
> Promise queue with concurrency control
Useful for rate-limiting async (or sync) operations. For example, when interacting with a REST API or when doing CPU/memory intensive tasks.
## Install
```
$ npm install p-queue
```
## Usage
Here we run only one promise at the time. For example, set `concurrency` to 4 to run four promises at the same time.
```js
const {default: PQueue} = require('p-queue');
const got = require('got');
const queue = new PQueue({concurrency: 1});
(async () => {
await queue.add(() => got('https://sindresorhus.com'));
console.log('Done: sindresorhus.com');
})();
(async () => {
await queue.add(() => got('https://avajs.dev'));
console.log('Done: avajs.dev');
})();
(async () => {
const task = await getUnicornTask();
await queue.add(task);
console.log('Done: Unicorn task');
})();
```
## API
### PQueue(options?)
Returns a new `queue` instance, which is an [`EventEmitter3`](https://github.com/primus/eventemitter3) subclass.
#### options
Type: `object`
##### concurrency
Type: `number`\
Default: `Infinity`\
Minimum: `1`
Concurrency limit.
##### timeout
Type: `number`
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
##### throwOnTimeout
Type: `boolean`\
Default: `false`
Whether or not a timeout is considered an exception.
##### autoStart
Type: `boolean`\
Default: `true`
Whether queue tasks within concurrency limit, are auto-executed as soon as they're added.
##### queueClass
Type: `Function`
Class with a `enqueue` and `dequeue` method, and a `size` getter. See the [Custom QueueClass](#custom-queueclass) section.
##### intervalCap
Type: `number`\
Default: `Infinity`\
Minimum: `1`
The max number of runs in the given interval of time.
##### interval
Type: `number`\
Default: `0`\
Minimum: `0`
The length of time in milliseconds before the interval count resets. Must be finite.
##### carryoverConcurrencyCount
Type: `boolean`\
Default: `false`
If `true`, specifies that any [pending](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) Promises, should be carried over into the next interval and counted against the `intervalCap`. If `false`, any of those pending Promises will not count towards the next `intervalCap`.
### queue
`PQueue` instance.
#### .add(fn, options?)
Adds a sync or async task to the queue. Always returns a promise.
##### fn
Type: `Function`
Promise-returning/async function.
#### options
Type: `object`
##### priority
Type: `number`\
Default: `0`
Priority of operation. Operations with greater priority will be scheduled first.
#### .addAll(fns, options?)
Same as `.add()`, but accepts an array of sync or async functions and returns a promise that resolves when all functions are resolved.
#### .pause()
Put queue execution on hold.
#### .start()
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.)
Returns `this` (the instance).
#### .onEmpty()
Returns a promise that settles when the queue becomes empty.
Can be called multiple times. Useful if you for example add additional items at a later time.
#### .onIdle()
Returns a promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
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.
#### .clear()
Clear the queue.
#### .size
Size of the queue.
#### .sizeBy(options)
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.
```js
const queue = new PQueue();
queue.add(async () => '🦄', {priority: 1});
queue.add(async () => '🦄', {priority: 0});
queue.add(async () => '🦄', {priority: 1});
console.log(queue.sizeBy({priority: 1}));
//=> 2
console.log(queue.sizeBy({priority: 0}));
//=> 1
```
#### .pending
Number of pending promises.
#### [.timeout](#timeout)
#### [.concurrency](#concurrency)
#### .isPaused
Whether the queue is currently paused.
## Events
#### active
Emitted as each item is processed in the queue for the purpose of tracking progress.
```js
const delay = require('delay');
const {default: PQueue} = require('p-queue');
const queue = new PQueue({concurrency: 2});
let count = 0;
queue.on('active', () => {
console.log(`Working on item #${++count}. Size: ${queue.size} Pending: ${queue.pending}`);
});
queue.add(() => Promise.resolve());
queue.add(() => delay(2000));
queue.add(() => Promise.resolve());
queue.add(() => Promise.resolve());
queue.add(() => delay(500));
```
#### idle
Emitted every time the queue becomes empty and all promises have completed; `queue.size === 0 && queue.pending === 0`.
```js
const delay = require('delay');
const {default: PQueue} = require('p-queue');
const queue = new PQueue();
queue.on('idle', () => {
console.log(`Queue is idle. Size: ${queue.size} Pending: ${queue.pending}`);
});
const job1 = queue.add(() => delay(2000));
const job2 = queue.add(() => delay(500));
await job1;
await job2;
// => 'Queue is idle. Size: 0 Pending: 0'
await queue.add(() => delay(600));
// => 'Queue is idle. Size: 0 Pending: 0'
```
The `idle` event is emitted every time the queue reaches an idle state. On the other hand, the promise the `onIdle()` function returns resolves once the queue becomes idle instead of every time the queue is idle.
#### add
Emitted every time the add method is called and the number of pending or queued tasks is increased.
#### next
Emitted every time a task is completed and the number of pending or queued tasks is decreased.
```js
const delay = require('delay');
const {default: PQueue} = require('p-queue');
const queue = new PQueue();
queue.on('add', () => {
console.log(`Task is added. Size: ${queue.size} Pending: ${queue.pending}`);
});
queue.on('next', () => {
console.log(`Task is completed. Size: ${queue.size} Pending: ${queue.pending}`);
});
const job1 = queue.add(() => delay(2000));
const job2 = queue.add(() => delay(500));
await job1;
await job2;
//=> 'Task is added. Size: 0 Pending: 1'
//=> 'Task is added. Size: 0 Pending: 2'
await queue.add(() => delay(600));
//=> 'Task is completed. Size: 0 Pending: 1'
//=> 'Task is completed. Size: 0 Pending: 0'
```
## Advanced example
A more advanced example to help you understand the flow.
```js
const delay = require('delay');
const {default: PQueue} = require('p-queue');
const queue = new PQueue({concurrency: 1});
(async () => {
await delay(200);
console.log(`8. Pending promises: ${queue.pending}`);
//=> '8. Pending promises: 0'
(async () => {
await queue.add(async () => '🐙');
console.log('11. Resolved')
})();
console.log('9. Added 🐙');
console.log(`10. Pending promises: ${queue.pending}`);
//=> '10. Pending promises: 1'
await queue.onIdle();
console.log('12. All work is done');
})();
(async () => {
await queue.add(async () => '🦄');
console.log('5. Resolved')
})();
console.log('1. Added 🦄');
(async () => {
await queue.add(async () => '🐴');
console.log('6. Resolved')
})();
console.log('2. Added 🐴');
(async () => {
await queue.onEmpty();
console.log('7. Queue is empty');
})();
console.log(`3. Queue size: ${queue.size}`);
//=> '3. Queue size: 1`
console.log(`4. Pending promises: ${queue.pending}`);
//=> '4. Pending promises: 1'
```
```
$ node example.js
1. Added 🦄
2. Added 🐴
3. Queue size: 1
4. Pending promises: 1
5. Resolved 🦄
6. Resolved 🐴
7. Queue is empty
8. Pending promises: 0
9. Added 🐙
10. Pending promises: 1
11. Resolved 🐙
12. All work is done
```
## Custom QueueClass
For implementing more complex scheduling policies, you can provide a QueueClass in the options:
```js
class QueueClass {
constructor() {
this._queue = [];
}
enqueue(run, options) {
this._queue.push(run);
}
dequeue() {
return this._queue.shift();
}
get size() {
return this._queue.length;
}
filter(options) {
return this._queue;
}
}
```
`p-queue` will call corresponding methods to put and get operations from this queue.
## Related
- [p-limit](https://github.com/sindresorhus/p-limit) - Run multiple promise-returning & async functions with limited concurrency
- [p-throttle](https://github.com/sindresorhus/p-throttle) - Throttle promise-returning & async functions
- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions
- [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
- [More…](https://github.com/sindresorhus/promise-fun)
---
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-p-queue?utm_source=npm-p-queue&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>