Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian De Sousa briandesousa

View GitHub Profile
@briandesousa
briandesousa / node-worker-thread-rxjs.js
Last active Feb 16, 2019
Demonstrating how to use Node worker_thread module with RxJS observable to stream data from a worker thread to it's parent thread.
View node-worker-thread-rxjs.js
const { workerData, parentPort } = require('worker_threads');
parentPort.postMessage(`starting heavy duty work from process ${process.pid} that will take ${workerData}s to complete`);
timeLimit = workerData;
timer = 0;
// simulate a long-running process with updates posted back on a regular interval
do {
setTimeout(
@briandesousa
briandesousa / node-parent-thread-rxjs.js
Last active Feb 16, 2019
Demonstrating how to use Node worker_thread module with RxJS observable to stream data from a worker thread to it's parent thread.
View node-parent-thread-rxjs.js
const Rxjs = require('rxjs');
const RxjsOperators = require('rxjs/operators');
const { Worker } = require('worker_threads');
console.log("\nNode multi-threading demo using worker_threads module in Node 11.7.0\n");
const COMPLETE_SIGNAL = 'COMPLETE';
function runTask(workerData, completedOnTime) {
return Rxjs.Observable.create(observer => {
You can’t perform that action at this time.