UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

36 lines 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.blockScope = void 0; const lifecycle_stack_js_1 = require("../web-assembly/emscripten/lifecycle-stack.js"); const _debug_js_1 = require("../debug/_debug.js"); /** * @public * Any shared objects allocated in the callback will be released on return. By default, these will be released on throw too. * In such event the error will be rethrown after releasing any shared objects. * * Error handling can be disabled by setting the build flag `WASM_DISABLE_STACK_LIFECYCLE_TRY_CATCH`. */ function blockScope(callback) { const blockScopedNode = lifecycle_stack_js_1.lifecycleStack.push(); let ret; // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions if (_BUILD.WASM_DISABLE_STACK_LIFECYCLE_TRY_CATCH) { ret = callback(); blockScopedNode.getLinked().unlinkAll(); lifecycle_stack_js_1.lifecycleStack.pop(); } else { try { ret = callback(); } finally { blockScopedNode.getLinked().unlinkAll(); lifecycle_stack_js_1.lifecycleStack.pop(); } } // you need to be very careful about ordering... block scope probably isn't appropriate for this _BUILD.DEBUG && _debug_js_1._Debug.assert(!(ret instanceof Promise), "found promise, this is not supported"); return ret; } exports.blockScope = blockScope; //# sourceMappingURL=block-scoped-lifecycle.js.map