parent
a8d7efe9ec
commit
11ce8149f9
1 changed files with 19 additions and 11 deletions
|
@ -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" }: {
|
||||
#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;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue