@augment-vir/node
Version:
A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.
19 lines (17 loc) • 593 B
text/typescript
import {type MaybePromise} from '@augment-vir/core';
import {killContainer} from './kill-container.js';
/**
* Runs a callback (which presumably runs a command within the given `containerName`) and kills the
* given `containerName` container if the callback fails.
*/
export async function tryOrKillContainer<T>(
containerNameOrId: string,
callback: (containerNameOrId: string) => MaybePromise<T>,
): Promise<Awaited<T>> {
try {
return await callback(containerNameOrId);
} catch (error) {
await killContainer(containerNameOrId);
throw error;
}
}