@temporalio/worker
Version:
Temporal.io SDK Worker sub-package
46 lines • 1.49 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.notifyRunner = notifyRunner;
const workflow_1 = require("@temporalio/workflow");
class WorkflowNotifier {
static _instance;
/**
* Access the singleton instance - one per workflow context
*/
static instance() {
if (this._instance === undefined) {
this._instance = new this();
}
return this._instance;
}
constructor() {
// Dear eslint,
// I left this empty to mark the constructor private, OK?
//
// Best regards,
// - An anonymous developer
}
lastNotifiedStartEvent = -1;
notifyRunner() {
const eventId = (0, workflow_1.workflowInfo)().historyLength;
if (this.lastNotifiedStartEvent >= eventId)
return;
this.lastNotifiedStartEvent = eventId;
try {
// Use global `notifyRunner` function, should be injected outside of workflow context.
// Using globalThis.constructor.constructor, we break out of the workflow context to Node.js land.
const notifyRunner = globalThis.constructor.constructor('return notifyRunner')();
notifyRunner(eventId);
}
catch {
// ignore
}
}
}
/**
* Notify a runner process when a workflow task is picked up
*/
function notifyRunner() {
WorkflowNotifier.instance().notifyRunner();
}
//# sourceMappingURL=workflow-notifier.js.map
;