Skip to content

Commit

Permalink
abort has the same effect as reject
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 4, 2024
1 parent ba50124 commit 031377b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/lib/create-prompt.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function createPrompt<Value, Config>(view: ViewFunction<Value, Config>) {
const prompt: Prompt<Value, Config> = (config, context = {}) => {
// Default `input` to stdin
const { input = process.stdin, signal: outsideSignal } = context;
const { promise, resolve, reject, abort, onFinally } =
const { promise, resolve, reject, onFinally } =
CancelablePromise.withResolver<Value>();

// Add mute capabilities to the output
Expand All @@ -39,7 +39,7 @@ export function createPrompt<Value, Config>(view: ViewFunction<Value, Config>) {

if (outsideSignal) {
const outsideAbort = () =>
abort(new AbortPromptError({ cause: outsideSignal.reason }));
reject(new AbortPromptError({ cause: outsideSignal.reason }));
if (outsideSignal.aborted) {
outsideAbort();
return promise;
Expand All @@ -51,7 +51,7 @@ export function createPrompt<Value, Config>(view: ViewFunction<Value, Config>) {
withHooks(rl, (cycle) => {
onFinally(
onSignalExit((code, signal) => {
abort(
reject(
new ExitPromptError(`User force closed the prompt with ${code} ${signal}`),
);
}),
Expand Down Expand Up @@ -102,7 +102,7 @@ export function createPrompt<Value, Config>(view: ViewFunction<Value, Config>) {

effectScheduler.run();
} catch (error: unknown) {
abort(error);
reject(error);
}
});
});
Expand Down
4 changes: 1 addition & 3 deletions packages/type/src/inquirer.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class CancelablePromise<T> extends Promise<T> {
abortController.signal.addEventListener('abort', () => reject(signal.reason), {
once: true,
});
const abort = (error: unknown) => abortController.abort(error);

const finallyCallbacks = new Set<() => void>();
const onFinally = (onfinally: () => void) => finallyCallbacks.add(onfinally);
Expand All @@ -32,15 +31,14 @@ export class CancelablePromise<T> extends Promise<T> {
});
});

promise.cancel = () => abort(new CancelPromptError());
promise.cancel = () => reject(new CancelPromptError());

return {
promise,
resolve: resolve!,
reject: reject!,
signal: abortController.signal,
onFinally,
abort,
};
}
}
Expand Down

0 comments on commit 031377b

Please sign in to comment.