fix: async.once was incorrectly written

closes #18
This commit is contained in:
clover caruso 2025-08-02 22:30:53 -04:00
parent a8d7efe9ec
commit 11ce8149f9

View file

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