UNPKG

@temporalio/workflow

Version:
40 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Trigger = void 0; const cancellation_scope_1 = require("./cancellation-scope"); const stack_helpers_1 = require("./stack-helpers"); /** * A `PromiseLike` helper which exposes its `resolve` and `reject` methods. * * Trigger is CancellationScope-aware: it is linked to the current scope on * construction and throws when that scope is cancelled. * * Useful for e.g. waiting for unblocking a Workflow from a Signal. * * @example * <!--SNIPSTART typescript-trigger-workflow--> * <!--SNIPEND--> */ class Trigger { constructor() { this.promise = new Promise((resolve, reject) => { const scope = cancellation_scope_1.CancellationScope.current(); if (scope.cancellable) { (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(reject)); } // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore this.resolve = resolve; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore this.reject = reject; }); // Avoid unhandled rejections (0, stack_helpers_1.untrackPromise)(this.promise.catch(() => undefined)); } then(onfulfilled, onrejected) { return this.promise.then(onfulfilled, onrejected); } } exports.Trigger = Trigger; //# sourceMappingURL=trigger.js.map