authorgravatar for git@paperclover.netclover caruso <git@paperclover.net> 2025-08-02 22:30:53-04:00
committergravatar for git@paperclover.netclover caruso <git@paperclover.net> 2025-10-14 02:40:46-07:00
logddb832eb2c15c9c3c1e00ab6882fead93ffd8c4b
treece9255dc3191704836f01838cc04159159263cc5
parent521edec76fecc043e04bedcf0c00c0368fa9e96e
signature Commit is signed but in an unrecognized format.

fix: `async.once` was incorrectly written

closes #18

1 files changed, 19 insertions(+), 11 deletions(-)

framework/lib/async.ts+19-11
...@@ -43,7 +43,7 @@ export class Queue<T, R> {...@@ -43,7 +43,7 @@ export class Queue<T, R> {
43 get bar() {43 get bar() {
44 const cached = this.#cachedProgress;44 const cached = this.#cachedProgress;
45 if (!cached) {45 if (!cached) {
46 const bar = this.#cachedProgress = new Progress({46 const bar = (this.#cachedProgress = new Progress({
47 spinner: null,47 spinner: null,
48 text: ({ active }) => {48 text: ({ active }) => {
49 const now = performance.now();49 const now = performance.now();
...@@ -51,8 +51,8 @@ export class Queue<T, R> {...@@ -51,8 +51,8 @@ export class Queue<T, R> {
51 let n = 0;51 let n = 0;
52 for (const item of active) {52 for (const item of active) {
53 let itemText = "- " + item.format(now);53 let itemText = "- " + item.format(now);
54 text += `\n` +54 text +=
55 itemText.slice(0, Math.max(0, process.stdout.columns - 1));55 `\n` + itemText.slice(0, Math.max(0, process.stdout.columns - 1));
56 if (n > 10) {56 if (n > 10) {
57 text += `\n ... + ${active.length - n} more`;57 text += `\n ... + ${active.length - n} more`;
58 break;58 break;
...@@ -64,7 +64,7 @@ export class Queue<T, R> {...@@ -64,7 +64,7 @@ export class Queue<T, R> {
64 props: {64 props: {
65 active: [] as Spinner[],65 active: [] as Spinner[],
66 },66 },
67 });67 }));
68 bar.value = 0;68 bar.value = 0;
69 return bar;69 return bar;
70 }70 }
...@@ -83,7 +83,10 @@ export class Queue<T, R> {...@@ -83,7 +83,10 @@ export class Queue<T, R> {
83 }83 }
8484
85 add(args: T) {85 add(args: T) {
86 return this.addReturn(args).then(() => {}, () => {});86 return this.addReturn(args).then(
87 () => {},
88 () => {},
89 );
87 }90 }
8891
89 addMany(items: T[]) {92 addMany(items: T[]) {
...@@ -164,11 +167,11 @@ export class Queue<T, R> {...@@ -164,11 +167,11 @@ export class Queue<T, R> {
164 this.#end(o);167 this.#end(o);
165 }168 }
166169
167 #end(170 #end({
168 { method = this.#passive ? "stop" : "success" }: {171 method = this.#passive ? "stop" : "success",
169 method?: "success" | "stop";172 }: {
170 } = {},173 method?: "success" | "stop";
171 ) {174 } = {}) {
172 const bar = this.#cachedProgress;175 const bar = this.#cachedProgress;
173 if (this.#errors.length > 0) {176 if (this.#errors.length > 0) {
174 if (bar) bar.stop();177 if (bar) bar.stop();
...@@ -287,7 +290,12 @@ export function once<T>(fn: () => Promise<T>): () => Promise<T> {...@@ -287,7 +290,12 @@ export function once<T>(fn: () => Promise<T>): () => Promise<T> {
287 let result: T | Promise<T> | null = null;290 let result: T | Promise<T> | null = null;
288 return async () => {291 return async () => {
289 if (result) return result;292 if (result) return result;
290 result = await fn();293 try {
294 result = await (result = fn());
295 } catch (err) {
296 result = null;
297 throw err;
298 }
291 return result;299 return result;
292 };300 };
293}301}