Skip to content

Commit

Permalink
chore: fixed test, after pnpm audit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed Jan 27, 2025
1 parent ebc5bc0 commit a659751
Showing 1 changed file with 108 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import path from 'node:path';
import fs from 'node:fs';
import { EventEmitter } from 'events';
import { encode } from 'gpt-tokenizer/model/gpt-4o';
import { l as logger, f as fetchSite, a as formatNumber, s as serializePages, e as ensureArray } from './packem_shared/index-BItZthxG.mjs';
import { l as logger, f as fetchSite, a as formatNumber, s as serializePages, e as ensureArray } from './packem_shared/index-DjmSPXQS.mjs';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
Expand Down Expand Up @@ -666,7 +666,7 @@ cli.parse();
export declare function fetchSite(url: string, options: Options): Promise<FetchSiteResult>;
export declare function serializePages(pages: FetchSiteResult, format: "json" | "text"): string;
",
"export { f as fetchSite, s as serializePages } from './packem_shared/index-BItZthxG.mjs';
"export { f as fetchSite, s as serializePages } from './packem_shared/index-DjmSPXQS.mjs';
import 'happy-dom';
import 'cheerio';
",
Expand Down Expand Up @@ -1032,15 +1032,24 @@ class PriorityQueue {
};
const element = {
priority: options.priority,
id: options.id,
run
};
if (this.size && this.#queue[this.size - 1].priority >= options.priority) {
if (this.size === 0 || this.#queue[this.size - 1].priority >= options.priority) {
this.#queue.push(element);
return;
}
const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
this.#queue.splice(index, 0, element);
}
setPriority(id, priority) {
const index = this.#queue.findIndex((element) => element.id === id);
if (index === -1) {
throw new ReferenceError(\`No promise function with the id "\${id}" exists in the queue.\`);
}
const [item] = this.#queue.splice(index, 1);
this.enqueue(item.run, { priority, id });
}
dequeue() {
const item = this.#queue.shift();
return item?.run;
Expand Down Expand Up @@ -1074,6 +1083,8 @@ class PQueue extends EventEmitter {
#concurrency;
#isPaused;
#throwOnTimeout;
// Use to assign a unique identifier to a promise function, if not explicitly specified
#idAssigner = 1n;
/**
Per-operation timeout in milliseconds. Operations fulfill once \`timeout\` elapses if they haven't already.

Expand Down Expand Up @@ -1212,7 +1223,47 @@ class PQueue extends EventEmitter {
}, { once: true });
});
}
/**
Updates the priority of a promise function by its id, affecting its execution order. Requires a defined concurrency limit to take effect.

For example, this can be used to prioritize a promise function to run earlier.

\`\`\`js
import PQueue from 'p-queue';

const queue = new PQueue({concurrency: 1});

queue.add(async () => '🦄', {priority: 1});
queue.add(async () => '🦀', {priority: 0, id: '🦀'});
queue.add(async () => '🦄', {priority: 1});
queue.add(async () => '🦄', {priority: 1});

queue.setPriority('🦀', 2);
\`\`\`

In this case, the promise function with \`id: '🦀'\` runs second.

You can also deprioritize a promise function to delay its execution:

\`\`\`js
import PQueue from 'p-queue';

const queue = new PQueue({concurrency: 1});

queue.add(async () => '🦄', {priority: 1});
queue.add(async () => '🦀', {priority: 1, id: '🦀'});
queue.add(async () => '🦄');
queue.add(async () => '🦄', {priority: 0});

queue.setPriority('🦀', -1);
\`\`\`
Here, the promise function with \`id: '🦀'\` executes last.
*/
setPriority(id, priority) {
this.#queue.setPriority(id, priority);
}
async add(function_, options = {}) {
options.id ??= (this.#idAssigner++).toString();
options = {
timeout: this.timeout,
throwOnTimeout: this.#throwOnTimeout,
Expand Down Expand Up @@ -3485,7 +3536,7 @@ import path from 'node:path';
import fs from 'node:fs';
import { EventEmitter } from 'events';
import { encode } from 'gpt-tokenizer/model/gpt-4o';
import { l as logger, f as fetchSite, a as formatNumber, s as serializePages, e as ensureArray } from './packem_shared/index-BItZthxG.mjs';
import { l as logger, f as fetchSite, a as formatNumber, s as serializePages, e as ensureArray } from './packem_shared/index-DjmSPXQS.mjs';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
Expand Down Expand Up @@ -4142,7 +4193,7 @@ cli.parse();
export declare function fetchSite(url: string, options: Options): Promise<FetchSiteResult>;
export declare function serializePages(pages: FetchSiteResult, format: "json" | "text"): string;
",
"export { f as fetchSite, s as serializePages } from './packem_shared/index-BItZthxG.mjs';
"export { f as fetchSite, s as serializePages } from './packem_shared/index-DjmSPXQS.mjs';
import 'happy-dom';
import 'cheerio';
",
Expand Down Expand Up @@ -4508,15 +4559,24 @@ class PriorityQueue {
};
const element = {
priority: options.priority,
id: options.id,
run
};
if (this.size && this.#queue[this.size - 1].priority >= options.priority) {
if (this.size === 0 || this.#queue[this.size - 1].priority >= options.priority) {
this.#queue.push(element);
return;
}
const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
this.#queue.splice(index, 0, element);
}
setPriority(id, priority) {
const index = this.#queue.findIndex((element) => element.id === id);
if (index === -1) {
throw new ReferenceError(\`No promise function with the id "\${id}" exists in the queue.\`);
}
const [item] = this.#queue.splice(index, 1);
this.enqueue(item.run, { priority, id });
}
dequeue() {
const item = this.#queue.shift();
return item?.run;
Expand Down Expand Up @@ -4550,6 +4610,8 @@ class PQueue extends EventEmitter {
#concurrency;
#isPaused;
#throwOnTimeout;
// Use to assign a unique identifier to a promise function, if not explicitly specified
#idAssigner = 1n;
/**
Per-operation timeout in milliseconds. Operations fulfill once \`timeout\` elapses if they haven't already.

Expand Down Expand Up @@ -4688,7 +4750,47 @@ class PQueue extends EventEmitter {
}, { once: true });
});
}
/**
Updates the priority of a promise function by its id, affecting its execution order. Requires a defined concurrency limit to take effect.

For example, this can be used to prioritize a promise function to run earlier.

\`\`\`js
import PQueue from 'p-queue';

const queue = new PQueue({concurrency: 1});

queue.add(async () => '🦄', {priority: 1});
queue.add(async () => '🦀', {priority: 0, id: '🦀'});
queue.add(async () => '🦄', {priority: 1});
queue.add(async () => '🦄', {priority: 1});

queue.setPriority('🦀', 2);
\`\`\`

In this case, the promise function with \`id: '🦀'\` runs second.

You can also deprioritize a promise function to delay its execution:

\`\`\`js
import PQueue from 'p-queue';

const queue = new PQueue({concurrency: 1});

queue.add(async () => '🦄', {priority: 1});
queue.add(async () => '🦀', {priority: 1, id: '🦀'});
queue.add(async () => '🦄');
queue.add(async () => '🦄', {priority: 0});

queue.setPriority('🦀', -1);
\`\`\`
Here, the promise function with \`id: '🦀'\` executes last.
*/
setPriority(id, priority) {
this.#queue.setPriority(id, priority);
}
async add(function_, options = {}) {
options.id ??= (this.#idAssigner++).toString();
options = {
timeout: this.timeout,
throwOnTimeout: this.#throwOnTimeout,
Expand Down

0 comments on commit a659751

Please sign in to comment.