From 4adc2abc47d9e25e1d9cf64542085ead916517f2 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Sat, 2 Aug 2025 22:30:53 -0400 Subject: [PATCH] fix: `async.once` was incorrectly written closes #18 --- framework/lib/async.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/framework/lib/async.ts b/framework/lib/async.ts index 3e7aee2..881fd48 100644 --- a/framework/lib/async.ts +++ b/framework/lib/async.ts @@ -43,7 +43,7 @@ export class Queue { 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 { 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 { props: { active: [] as Spinner[], }, - }); + })); bar.value = 0; return bar; } @@ -83,7 +83,10 @@ export class Queue { } add(args: T) { - return this.addReturn(args).then(() => {}, () => {}); + return this.addReturn(args).then( + () => {}, + () => {}, + ); } addMany(items: T[]) { @@ -164,11 +167,11 @@ export class Queue { 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(fn: () => Promise): () => Promise { let result: T | Promise | null = null; return async () => { if (result) return result; - result = await fn(); + try { + result = await (result = fn()); + } catch (err) { + result = null; + throw err; + } return result; }; }