Files
reverse-engineering-anything/src/process/AbortablePromise.ts
T
morlutoandmorluto 1eca600515 fix(apktool): resolve Windows PATH launchers before invocation (#2802)
* fix(apktool): resolve Windows PATH launchers before invocation

Resolve the default launcher through the selected PATH/PATHEXT before choosing native process creation or the existing conservative cmd.exe wrapper. Reuse the resulting selection and one canonical environment for the version probe and decode.

Follow-up to the release #1693 review of #1777. Source inspected and formatted; tests, builds, check reruns and real Windows Apktool execution were skipped at maintainer request.

* fix(apktool): bound lookup and retain only selected environment

Source inspection and targeted formatting only. Tests, builds, lint, typechecks and provider workloads were not run at the user's explicit request.

* fix(apktool): use supported timeout diagnostics

Retain lookup phase through AnalysisErrorOptions diagnostics while preserving the operation and timeout identity. Source inspection and targeted formatting only; tests, checks, builds and provider workloads were skipped at the user request.

---------

Co-authored-by: morluto <morluto@users.noreply.github.com>
2026-10-13 22:00:47 +08:00

30 lines
1.0 KiB
TypeScript

/** Sentinel returned when an abort signal wins an asynchronous race. */
export const ABORTED = Symbol("aborted");
/**
* Await a promise without depending on the producer to observe cancellation.
* The producer still receives its signal separately and remains responsible for
* releasing any resources that it owns.
*/
export const waitForAbortable = async <Value>(
pending: Promise<Value>,
signal: AbortSignal | undefined,
): Promise<Value | typeof ABORTED> => {
if (signal === undefined) return pending;
let onAbort: (() => void) | undefined;
const cancelled = new Promise<typeof ABORTED>((resolve) => {
if (signal.aborted) {
resolve(ABORTED);
return;
}
onAbort = () => resolve(ABORTED);
signal.addEventListener("abort", onAbort, { once: true });
});
try {
// Even an already-cancelled wait must own the producer's eventual rejection.
return await Promise.race([cancelled, pending]);
} finally {
if (onAbort !== undefined) signal.removeEventListener("abort", onAbort);
}
};