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AG,CAAC,CAAA;QACT,GAAG,CAAC,CAAC,IAAI,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC;YACzB,MAAM,MAAM,GAAG,SAAS,GAAG,CAAC,EAAE,GAAG,GAAG,CAAA;YACpC,CAAC,IAAI,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,KAAK,CAAA;QAC5D,CAAC;QACD,MAAM,CAAC,CAAC,CAAA;IACV,CAAC;AACH,CAAC;AAVY,mBAAW,cAUvB,CAAA;AAED,aAAoB,QAA6B;IAC/C,MAAM,MAAM,GAAiB,EAAE,CAAA;IAC/B,MAAM,CAAC,kBAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAC5E,IAAI,CAAC;QACJ,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;YACxB,MAAM,MAAM,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;QACD,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;YAC3B,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;QACnD,CAAC;IACH,CAAC,CAAC,CAAA;AACN,CAAC;AAXe,WAAG,MAWlB,CAAA","sourcesContent":["import { Promise as BluebirdPromise } from \"bluebird\"\nimport { tsAwaiter } from \"./awaiter\"\n\nconst __awaiter = tsAwaiter\nArray.isArray(__awaiter)\n\nexport function printErrorAndExit(error: Error) {\n console.error(error.stack || error.message || error)\n process.exit(-1)\n}\n\n// you don't need to handle error in your task - it is passed only indicate status of promise\nexport async function executeFinally(promise: Promise<any>, task: (error?: Error) => Promise<any>): Promise<any> {\n let result: any = null\n try {\n result = await promise\n }\n catch (originalError) {\n try {\n await task(originalError)\n }\n catch (taskError) {\n throw new NestedError([originalError, taskError])\n }\n\n throw originalError\n }\n\n try {\n await task(null)\n }\n catch (taskError) {\n throw taskError\n }\n return result\n}\n\nexport class NestedError extends Error {\n constructor(errors: Array<Error>, message: string = \"Compound error: \") {\n let m = message\n let i = 1\n for (let error of errors) {\n const prefix = \"Error #\" + i++ + \" \"\n m += \"\\n\\n\" + prefix + \"-\".repeat(80) + \"\\n\" + error.stack\n }\n super(m)\n }\n}\n\nexport function all(promises: Array<Promise<any>>): BluebirdPromise<any> {\n const errors: Array<Error> = []\n return BluebirdPromise.all(promises.map(it => it.catch(it => errors.push(it))))\n .then(() => {\n if (errors.length === 1) {\n throw errors[0]\n }\n else if (errors.length > 1) {\n throw new NestedError(errors, \"Cannot cleanup: \")\n }\n })\n}"]}
\No newline at end of file