From 055f138e47495b4e91a5a2c04d43cc77a0ccef1c Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Mon, 30 Sep 2024 13:26:09 -0300 Subject: [PATCH] fix(adapter): fix queue types (#41) --- workspaces/adapter/src/queued-adapter.ts | 13 +++++++------ workspaces/adapter/src/testing/test-adapter.ts | 4 ++-- workspaces/adapter/types/adapter.d.ts | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/workspaces/adapter/src/queued-adapter.ts b/workspaces/adapter/src/queued-adapter.ts index 012119f..9863458 100644 --- a/workspaces/adapter/src/queued-adapter.ts +++ b/workspaces/adapter/src/queued-adapter.ts @@ -103,7 +103,8 @@ export class QueuedAdapter implements QueuedAdapterApi { async prompt(questions: PromptQuestions, initialAnswers?: Partial): Promise { return this.#queue.add(async () => this.actualAdapter.prompt(questions, initialAnswers), { priority: PROMPT_PRIORITY + this.delta, - }) as any; + throwOnTimeout: true, + }); } async onIdle() { @@ -115,8 +116,8 @@ export class QueuedAdapter implements QueuedAdapterApi { * @param fn * @returns */ - async queue(function_: Task): Promise { - return this.#queue.add(() => function_(this.actualAdapter), { priority: BLOCKING_PRIORITY + this.delta }); + async queue(function_: Task): Promise { + return this.#queue.add(() => function_(this.actualAdapter), { priority: BLOCKING_PRIORITY + this.delta, throwOnTimeout: true }); } /** @@ -124,8 +125,8 @@ export class QueuedAdapter implements QueuedAdapterApi { * @param fn * @returns */ - async queueLog(function_: Task): Promise { - return this.#queue.add(() => function_(this.actualAdapter), { priority: LOG_PRIORITY + this.delta }); + async queueLog(function_: Task): Promise { + return this.#queue.add(() => function_(this.actualAdapter), { priority: LOG_PRIORITY + this.delta, throwOnTimeout: true }); } /** @@ -134,7 +135,7 @@ export class QueuedAdapter implements QueuedAdapterApi { * @param options * @returns */ - async progress(function_: ProgressCallback, options?: ProgressOptions): Promise { + async progress(function_: ProgressCallback, options?: ProgressOptions): Promise { if (this.#queue.size > 0 || this.#queue.pending > 0 || options?.disabled || this.#ora.isSpinning) { // Don't show progress if queue is not empty or already spinning. return Promise.resolve(function_({ step() {} })).finally(() => { diff --git a/workspaces/adapter/src/testing/test-adapter.ts b/workspaces/adapter/src/testing/test-adapter.ts index 469d31d..9d224e5 100644 --- a/workspaces/adapter/src/testing/test-adapter.ts +++ b/workspaces/adapter/src/testing/test-adapter.ts @@ -146,7 +146,7 @@ export class TestAdapter impleme } } - async queue(function_: Task): Promise { + async queue(function_: Task): Promise { return function_(this); } @@ -154,7 +154,7 @@ export class TestAdapter impleme function_: (progress: { step: (prefix: string, message: string, ...arguments_: any[]) => void }) => ReturnType, _options?: { disabled?: boolean | undefined; name?: string | undefined } | undefined, - ): Promise { + ): Promise { return function_({ step() {} }); } diff --git a/workspaces/adapter/types/adapter.d.ts b/workspaces/adapter/types/adapter.d.ts index 267c2c8..6e84c8f 100644 --- a/workspaces/adapter/types/adapter.d.ts +++ b/workspaces/adapter/types/adapter.d.ts @@ -48,6 +48,6 @@ export type ProgressCallback = (progress: { export type ProgressOptions = { disabled?: boolean; name?: string }; export type QueuedAdapter = InputOutputAdapter & { - queue(function_: Task): Promise; - progress(function_: ProgressCallback, options?: ProgressOptions): Promise; + queue(function_: Task): Promise; + progress(function_: ProgressCallback, options?: ProgressOptions): Promise; };