UNPKG

pandora

Version:

A powerful and lightweight application manager for Node.js applications powered by TypeScript.

39 lines (32 loc) 718 B
import wrap = require('spawn-wrap'); const wrapFile = require.resolve('./spawnWrapper'); export class SpawnWrapperUtils { private static unwrapFn: () => void; static wrap() { if (!SpawnWrapperUtils.unwrapFn) { SpawnWrapperUtils.unwrapFn = wrap([wrapFile]); } } static unwrap() { if (SpawnWrapperUtils.unwrapFn) { this.unwrapFn(); this.unwrapFn = null; } } static async transaction(fn) { SpawnWrapperUtils.wrap(); let ret; let caughtError; try { ret = await fn(); } catch (error) { caughtError = error; } finally { SpawnWrapperUtils.unwrap(); } if (caughtError) { throw caughtError; } return ret; } }