UNPKG

@temporalio/workflow

Version:
41 lines 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UpdateScope = exports.AsyncLocalStorage = void 0; exports.disableUpdateStorage = disableUpdateStorage; // AsyncLocalStorage is injected via vm module into global scope. // In case Workflow code is imported in Node.js context, replace with an empty class. exports.AsyncLocalStorage = globalThis.AsyncLocalStorage ?? class { }; class UpdateScope { constructor(options) { this.id = options.id; this.name = options.name; } /** * Activate the scope as current and run the update handler `fn`. * * @return the result of `fn` */ run(fn) { return storage.run(this, fn); } /** * Get the current "active" update scope. */ static current() { return storage.getStore(); } /** Alias to `new UpdateScope({ id, name }).run(fn)` */ static updateWithInfo(id, name, fn) { return new this({ id, name }).run(fn); } } exports.UpdateScope = UpdateScope; const storage = new exports.AsyncLocalStorage(); /** * Disable the async local storage for updates. */ function disableUpdateStorage() { storage.disable(); } //# sourceMappingURL=update-scope.js.map