fix: async.once was incorrectly written

closes #18
This commit is contained in:
clover caruso 2025-08-02 22:30:53 -04:00
parent 30ad9c27ff
commit 4adc2abc47

View file

@ -43,7 +43,7 @@ export class Queue<T, R> {
get bar() {
const cached = this.#cachedProgress;
if (!cached) {
const bar = this.#cachedProgress = new Progress({
const bar = (this.#cachedProgress = new Progress({
spinner: null,
text: ({ active }) => {
const now = performance.now();
@ -51,8 +51,8 @@ export class Queue<T, R> {
let n = 0;
for (const item of active) {
let itemText = "- " + item.format(now);
text += `\n` +
itemText.slice(0, Math.max(0, process.stdout.columns - 1));
text +=
`\n` + itemText.slice(0, Math.max(0, process.stdout.columns - 1));
if (n > 10) {
text += `\n ... + ${active.length - n} more`;
break;
@ -64,7 +64,7 @@ export class Queue<T, R> {
props: {
active: [] as Spinner[],
},
});
}));
bar.value = 0;
return bar;
}
@ -83,7 +83,10 @@ export class Queue<T, R> {
}
add(args: T) {
return this.addReturn(args).then(() => {}, () => {});
return this.addReturn(args).then(
() => {},
() => {},
);
}
addMany(items: T[]) {
@ -164,11 +167,11 @@ export class Queue<T, R> {
this.#end(o);
}
#end(
{ method = this.#passive ? "stop" : "success" }: {
method?: "success" | "stop";
} = {},
) {
#end({
method = this.#passive ? "stop" : "success",
}: {
method?: "success" | "stop";
} = {}) {
const bar = this.#cachedProgress;
if (this.#errors.length > 0) {
if (bar) bar.stop();
@ -287,7 +290,12 @@ export function once<T>(fn: () => Promise<T>): () => Promise<T> {
let result: T | Promise<T> | null = null;
return async () => {
if (result) return result;
result = await fn();
try {
result = await (result = fn());
} catch (err) {
result = null;
throw err;
}
return result;
};
}