INNER CODE UNIT · TypeScript
cleanupOnError
yume-chan/ya-webadb · libraries/adb-compression-zstd/src/index.ts:54
function cleanupOnError<T>(worker: Worker | undefined, callback: () => T): T {
if (!worker) {
return callback();
}
try {
const result = callback();
if (result instanceof Promise) {
return result.catch((e) => {
worker.terminate();
throw e;
}) as T;
}
return result;
} catch (e) {
worker.terminate();
throw e;
}