@hotmeshio/hotmesh
Version:
Serverless Workflow
36 lines (35 loc) • 1.26 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitFor = void 0;
const common_1 = require("./common");
const didRun_1 = require("./didRun");
/**
* Pauses the workflow until a signal with the given `signalId` is received.
*
* @template T
* @param {string} signalId - A unique signal identifier shared by the sender and receiver.
* @returns {Promise<T>} The data payload associated with the received signal.
*/
async function waitFor(signalId) {
const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)('wait');
if (didRunAlready) {
return result.data.data;
}
const store = common_1.asyncLocalStorage.getStore();
const interruptionRegistry = store.get('interruptionRegistry');
const workflowId = store.get('workflowId');
const workflowDimension = store.get('workflowDimension') ?? '';
const interruptionMessage = {
workflowId,
signalId,
index: execIndex,
workflowDimension,
};
interruptionRegistry.push({
code: common_1.HMSH_CODE_MESHFLOW_WAIT,
...interruptionMessage,
});
await (0, common_1.sleepImmediate)();
throw new common_1.MeshFlowWaitForError(interruptionMessage);
}
exports.waitFor = waitFor;
;