@hotmeshio/hotmesh
Version:
Serverless Workflow
29 lines (28 loc) • 1.1 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.signal = void 0;
const common_1 = require("./common");
const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
/**
* Sends a signal payload to any paused workflow thread awaiting this signal.
* @param {string} signalId - Unique signal identifier.
* @param {Record<any, any>} data - The payload to send with the signal.
* @returns {Promise<string>} The resulting hook/stream ID.
*/
async function signal(signalId, data) {
const store = common_1.asyncLocalStorage.getStore();
const workflowTopic = store.get('workflowTopic');
const connection = store.get('connection');
const namespace = store.get('namespace');
const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
connection,
namespace,
});
if (await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'signal')) {
return await hotMeshClient.hook(`${namespace}.wfs.signal`, {
id: signalId,
data,
});
}
}
exports.signal = signal;
;