UNPKG

redis-smq-common

Version:

RedisSMQ Common Library provides many components that are mainly used by RedisSMQ and RedisSMQ Monitor.

44 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleWorkerRunnable = handleWorkerRunnable; const index_js_1 = require("../types/index.js"); const worker_thread_message_js_1 = require("./worker-thread-message.js"); function handleWorkerRunnable(worker, messagePort, initialPayload) { let instance = null; try { instance = worker(initialPayload); } catch (err) { (0, worker_thread_message_js_1.exit)(index_js_1.EWorkerThreadChildExitCode.INVALID_WORKER_TYPE, err); } if (!instance || typeof instance !== 'object' || !(instance === null || instance === void 0 ? void 0 : instance.run) || !(instance === null || instance === void 0 ? void 0 : instance.shutdown)) { (0, worker_thread_message_js_1.exit)(index_js_1.EWorkerThreadChildExitCode.INVALID_WORKER_TYPE); } else { const run = () => { try { instance === null || instance === void 0 ? void 0 : instance.run((err) => { if (err) (0, worker_thread_message_js_1.exit)(index_js_1.EWorkerThreadChildExecutionCode.PROCESSING_ERROR, err); }); } catch (err) { (0, worker_thread_message_js_1.exit)(index_js_1.EWorkerThreadChildExecutionCode.PROCESSING_CAUGHT_ERROR, err); } }; const shutdown = () => { instance === null || instance === void 0 ? void 0 : instance.shutdown(() => void 0); }; const onMessage = (message) => { if (message.type === index_js_1.EWorkerThreadParentMessage.RUN) run(); if (message.type === index_js_1.EWorkerThreadParentMessage.SHUTDOWN) shutdown(); }; messagePort.on('message', onMessage); } } //# sourceMappingURL=worker-thread-runnable.js.map