INNER CODE UNIT · JavaScript
JavaToJSNotifier
SoftInstigate/restheart · polyglot/src/js/restheart.js:67
function JavaToJSNotifier() {
this.queue = queue;
this.worker = new Worker(`
const { workerData, parentPort } = require('worker_threads');
while (true) {
// block the worker waiting for the next notification from RESTHeart
var data = workerData.queue.take();
// notify the main event loop that we got new data
parentPort.postMessage(data);
}`,
{ eval: true, workerData: { queue: this.queue } });
}
// register a callback to be executed when something is added to the shared queue
const asyncJavaEvents = new JavaToJSNotifier();
asyncJavaEvents.worker.on('message', (n) => {
const type = n[0];