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> {
4343 get bar() {
4444 const cached = this.#cachedProgress;
4545 if (!cached) {
46 const bar = this.#cachedProgress = new Progress({
46 const bar = (this.#cachedProgress = new Progress({
4747 spinner: null,
4848 text: ({ active }) => {
4949 const now = performance.now();
......@@ -51,8 +51,8 @@ export class Queue<T, R> {
5151 let n = 0;
5252 for (const item of active) {
5353 let itemText = "- " + item.format(now);
54 text += `\n` +
55 itemText.slice(0, Math.max(0, process.stdout.columns - 1));
54 text +=
55 `\n` + itemText.slice(0, Math.max(0, process.stdout.columns - 1));
5656 if (n > 10) {
5757 text += `\n ... + ${active.length - n} more`;
5858 break;
......@@ -64,7 +64,7 @@ export class Queue<T, R> {
6464 props: {
6565 active: [] as Spinner[],
6666 },
67 });
67 }));
6868 bar.value = 0;
6969 return bar;
7070 }
......@@ -83,7 +83,10 @@ export class Queue<T, R> {
8383 }
8484
8585 add(args: T) {
86 return this.addReturn(args).then(() => {}, () => {});
86 return this.addReturn(args).then(
87 () => {},
88 () => {},
89 );
8790 }
8891
8992 addMany(items: T[]) {
......@@ -164,11 +167,11 @@ export class Queue<T, R> {
164167 this.#end(o);
165168 }
166169
167 #end(
168 { method = this.#passive ? "stop" : "success" }: {
169 method?: "success" | "stop";
170 } = {},
171 ) {
170 #end({
171 method = this.#passive ? "stop" : "success",
172 }: {
173 method?: "success" | "stop";
174 } = {}) {
172175 const bar = this.#cachedProgress;
173176 if (this.#errors.length > 0) {
174177 if (bar) bar.stop();
......@@ -287,7 +290,12 @@ export function once<T>(fn: () => Promise<T>): () => Promise<T> {
287290 let result: T | Promise<T> | null = null;
288291 return async () => {
289292 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 }
291299 return result;
292300 };
293301}