{"id":24070,"date":"2019-02-19T12:15:46","date_gmt":"2019-02-19T10:15:46","guid":{"rendered":"https:\/\/www.webcodegeeks.com\/?p=24070"},"modified":"2019-02-19T11:31:08","modified_gmt":"2019-02-19T09:31:08","slug":"using-node-11-7-worker-threads-rxjs","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/","title":{"rendered":"Using Node 11.7 Worker Threads with RxJS Observable"},"content":{"rendered":"\n<p>With the release of Node 11.7, the worker_threads module becomes a standard feature and is no longer hidden behind the <code>--experimental-worker<\/code> switch. The worker_threads module allows developers to run JavaScript asynchronously in light-weight, isolated threads contained within the main Node process. This article will be focusing on how use worker threads to execute a task asynchronously and stream data from that task back to the rest of your Node application using RxJS Observables.<\/p>\n\n\n\n<p>With the release of Node 11.7, the worker_threads module becomes a standard feature and is no longer hidden behind the <code>--experimental-worker<\/code> switch. The worker_threads module allows developers to run JavaScript asynchronously in light-weight, isolated threads contained within the main Node process. This article will be focusing on how use worker threads to execute a task asynchronously and stream data from that task back to the rest of your Node application using RxJS Observables.<\/p>\n\n\n\n<p>Before we get started, if you want to learn more about worker threads and why you might want to use them, I would recommend reading <a href=\"https:\/\/blog.logrocket.com\/node-js-multithreading-what-are-worker-threads-and-why-do-they-matter-48ab102f8b10\" target=\"_blank\" rel=\"noopener noreferrer\">Node.js multithreading: What are Worker Threads and why do they matter?<\/a> by&nbsp;<a href=\"https:\/\/blog.logrocket.com\/@gimenete\" target=\"_blank\" rel=\"noopener noreferrer\">Alberto Gimeno.<\/a>&nbsp;Alberto has done a fantastic job explaining the purpose of the worker_thread module, provided some solid examples of where it makes sense to use it as well as demonstrated some alternate ways to build a multi-threaded Node app.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are we building?<\/h2>\n\n\n\n<p>We are going to be building a simple Node app that creates a worker thread running a simulated long-running task that reports status back at regular intervals until it completes or until time runs out. The worker thread will be wrapped in an RxJS Observable so that the rest of the application can stream messages returned from the worker thread using the powerful RxJS library.<\/p>\n\n\n\n<p><strong>If you want to jump ahead and see the final solution, you can see it out on GitHub at <a href=\"https:\/\/github.com\/briandesousa\/node-worker-thread-rxjs\" target=\"_blank\" rel=\"noopener noreferrer\">briandesousa\/node-worker-thread-rxjs<\/a>.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up your environment<\/h2>\n\n\n\n<p>The first thing we need to do is ensure our environment is ready to go:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Install Node 11.7.0+<\/li><li>Use&nbsp;<code>npm init<\/code> to initialize a new NPM package<\/li><li>Add a simple start script to the package.json to start the app:&nbsp;<code>node node-parent-thread-rxjs.js<\/code><\/li><li>Install the RxJS package with&nbsp;<code>npm install -s rxjs<\/code><\/li><li>Create node-parent-thread-rxjs.js which will contain code running on the main thread<\/li><li>Create node-worker-thread-rxjs.js which will contain the implementation of the long-running task running on a separate thread<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Creating the worker thread<\/h2>\n\n\n\n<p>The worker thread has the logic to simulate a long-running task:<\/p>\n\n\n\n<pre class=\"brush:js\">\nconst { workerData, parentPort } = require('worker_threads');\n\nparentPort.postMessage(`starting heavy duty work from process ${process.pid} that will take ${workerData}s to complete`);\n\ntimeLimit = workerData;\ntimer = 0;\n\n\/\/ simulate a long-running process with updates posted back on a regular interval\ndo {\n    setTimeout(\n        (count) =&gt; {\n            parentPort.postMessage(`heavy duty work in progress...${count + 1}s`);\n            if (count === timeLimit) {\n                parentPort.postMessage('done heavy duty work');\n            }\n        },\n        1000 * timer,\n        timer);\n} while (++timer !== timeLimit);\n<\/pre>\n\n\n\n<p>Let\u2019s break this script down a bit:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>We use <code>parentPort<\/code> from the <code>worker_threads<\/code> modules to communicate back to the parent thread at 3 different points: <ul><li>before the task begins<\/li><li>while the task is running (within the do while loop) to provide status back to the parent thread<\/li><li>when the task completes<p><br><\/p><\/li><\/ul><\/li><li>We use <code>workerData<\/code> from the <code>worker_threads<\/code> module to pass in a time limit for how long (in seconds) the task should run for. The task completes when this time limit is reached (line 19).<\/li><\/ul>\n\n\n\n<p>This worker thread doesn\u2019t do anything particularly useful but it does demonstrate how a thread might receive instructions from its parent and stream multiple updates back to its parent.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating the parent thread<\/h2>\n\n\n\n<p>The parent thread has the following responsibilities:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Start the worker thread, specifying how long the worker thread should run for. We will call this WORKER_TIME.<\/li><li>Receiving updates from the worker thread in an observable stream<\/li><li>Exit the application if the worker thread takes too long. We will call this MAX_WAIT_TIME.<\/li><\/ul>\n\n\n\n<pre class=\"brush:java\">\nconst Rxjs = require('rxjs');\nconst RxjsOperators = require('rxjs\/operators');\nconst { Worker } = require('worker_threads');\n\nconsole.log(\"\\nNode multi-threading demo using worker_threads module in Node 11.7.0\\n\");\n\nconst COMPLETE_SIGNAL = 'COMPLETE';\n\nfunction runTask(workerData, completedOnTime) {\n    return Rxjs.Observable.create(observer =&gt; {\n        const worker = new Worker('.\/node-worker-thread-rxjs.js', { workerData });\n        worker.on('message', message =&gt; observer.next(message));\n        worker.on('error', error =&gt; observer.error(error));\n        worker.on('exit', code =&gt; {\n            if (code !== 0) {\n                observer.error(`Worker stopped with exit code ${code}`);\n            } else {\n                completedOnTime();\n                observer.next(COMPLETE_SIGNAL);\n                observer.complete();\n            }\n        });\n    });\n}\n\nconst MAX_WAIT_TIME = 3;\nconst WORKER_TIME = 10;\n\nfunction main() {\n    completedOnTime = false;\n\n    console.log(`[Main] Starting worker from process ${process.pid}`);\n\n    const worker$ = runTask(WORKER_TIME, () =&gt; completedOnTime = true);\n\n    \/\/ receive messages from worker until it completes but only wait for MAX_WAIT_TIME\n    worker$.pipe(\n        RxjsOperators.takeWhile(message =&gt; message !== COMPLETE_SIGNAL),\n        RxjsOperators.takeUntil(Rxjs.timer(MAX_WAIT_TIME * 1000))\n    ).subscribe(\n        result =&gt; console.log(`[Main] worker says: ${result}`),\n        error =&gt; console.error(`[Main] worker error: ${error}`),\n        () =&gt; {\n            if (!completedOnTime) {\n                console.log(`[Main] worker could not complete its work in the allowed ${MAX_WAIT_TIME}s, exiting Node process`);\n                process.exit(0);\n            } else {\n                console.log(`[Main] worker completed its work in the allowed ${WORKER_TIME}s`);\n            }\n        }\n    );\n}\n\nmain();\n<\/pre>\n\n\n\n<p>There is a lot going on here. Let\u2019s focus on the <code>runTask()<\/code> function first:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>We use <code>Observerable.create()<\/code> from the <code>rxjs<\/code> package to create a new observable. This observable creates an instance of the worker thread and passes some data in.<\/li><li>We map events output from the worker thread to the appropriate functions on the <a rel=\"noreferrer noopener\" aria-label=\"Observer  (opens in a new tab)\" href=\"http:\/\/reactivex.io\/rxjs\/class\/es6\/MiscJSDoc.js~ObserverDoc.html\" target=\"_blank\">Observer <\/a>interface: <ul><li><code>message<\/code> events are returned as normal values pushed to the subscriber through <code>Observer.next()<\/code><\/li><li><code>error<\/code> events are mapped to <code>Observer.error()<\/code><\/li><li>when an <code>exit<\/code> message is received, we check the message to determine why the worker thread exited: <ul><li>if a non-zero value is returned, then we know something went wrong and map the result to <code>Observer.error()<\/code><\/li><li>if zero is returned, we call a callback function to notify the application that the task was completed on time, we send one final special COMPLETE_SIGNAL value and then we complete the observable with <code>Observer.complete()<\/code><br><\/li><\/ul><\/li><\/ul><\/li><\/ul>\n\n\n\n<p>The <code>runTask()<\/code> doesn\u2019t have a very descriptive name however you can now see that it encapsulates the mapping logic between worker thread events and the Observable interface.<\/p>\n\n\n\n<p>Next, let\u2019s look at the at the <code>main()<\/code> function:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>We create the observable by calling <code>runTask()<\/code>. We pass in a simple callback that sets the <code>completedOnTime<\/code> flag to true so that we can report the reason why the observable completed. <ul><li>Note that the observable we just created is a <a href=\"http:\/\/reactivex.io\/documentation\/observable.html\">cold observable<\/a>. It creates the worker thread and starts emitting events only once it has been subscribed to. <br><\/li><\/ul><\/li><li>We pipe some RxJS operator functions into the observable: <ul><li><code>takeWhile()<\/code> to stop the stream when the special COMPLETE_SIGNAL value is received<\/li><li><code>takeUntil()<\/code> to stop the stream when time has run out <p><br><\/p><\/li><\/ul><\/li><li>We subscribe to the observable and log any values or errors that are received to the console. When the observable completes, we log the reason why it completed. If the reason is because we ran out of time, then we forcefully exit the application with <code>process.exit(0)<\/code>.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Running the solution<\/h2>\n\n\n\n<p>Run the solution with your <code>npm&nbsp;start<\/code> command. Assuming MAX_WAIT_TIME is still set to 3 and WORKER_TIME is set to 10, you will see the following output:<\/p>\n\n\n\n<div>\n<div id=\"highlighter_95114\" class=\"syntaxhighlighter  c\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"c plain\">Node multi-threading demo <\/code><code class=\"c keyword bold\">using<\/code> <code class=\"c plain\">worker_threads module in Node 11.7.0<\/code><\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;<\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"c plain\">[Main] Starting worker from process 4764<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"c plain\">[Main] worker says: starting heavy duty work from process 4764 that will take 10s to complete<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"c plain\">[Main] worker says: heavy duty work in progress...1s<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"c plain\">[Main] worker says: heavy duty work in progress...2s<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"c plain\">[Main] worker says: heavy duty work in progress...3s<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"c plain\">[Main] worker could not complete its work in the allowed 3s, exiting Node process<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n\n\n\n<p>The worker thread started to do its work, but after 3 seconds, the app signaled to stop the stream. The main process was forcefully exited along with the worker thread before it had a chance to complete its task.<\/p>\n\n\n\n<p>You can also try adjusting the solution to see what happens when:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>WORKER_TIME is less than MAX_WAIT_TIME<\/li><li>multiple worker threads are spawned from the parent thread by calling <code>runTask()<\/code> multiple times and creating multiple observables with different settings<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Wrap up<\/h2>\n\n\n\n<p>We have only just scratched the surface of what is possible when you combine the streaming power and beauty of RxJS Observables with the worker_threads module. Happy threading!<\/p>\n\n\n\n<p>Check out the full solution on GitHub at <a href=\"https:\/\/github.com\/briandesousa\/node-worker-thread-rxjs\" target=\"_blank\" rel=\"noreferrer noopener\">briandesousa\/node-worker-thread-rxjs<\/a>.<\/p>\n\n\n\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Web Code Geeks with permission by Brian De Sousa, partner at our <a href=\"\/\/www.webcodegeeks.com\/join-us\/wcg\/\" target=\"_blank\" rel=\"noopener\">WCG program<\/a>. See the original article here: <a href=\"https:\/\/briandesousa.net\/2019\/02\/16\/using-node-11-worker-threads-with-rxjs-observable\/\" target=\"_blank\" rel=\"noopener\">Using Node 11.7 Worker Threads with RxJS Observable<\/a><\/p>\n<p>Opinions expressed by Web Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>With the release of Node 11.7, the worker_threads module becomes a standard feature and is no longer hidden behind the &#8211;experimental-worker switch. The worker_threads module allows developers to run JavaScript asynchronously in light-weight, isolated threads contained within the main Node process. This article will be focusing on how use worker threads to execute a task &hellip;<\/p>\n","protected":false},"author":141,"featured_media":924,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-24070","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using Node 11.7 Worker Threads with RxJS Observable - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Interested to learn about RxJS Observable? Check our article explaining how to use worker threads to execute a task asynchronously with RxJS Observable.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Node 11.7 Worker Threads with RxJS Observable - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about RxJS Observable? Check our article explaining how to use worker threads to execute a task asynchronously with RxJS Observable.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-19T10:15:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Brian De Sousa\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@briandesousa1\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brian De Sousa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/\"},\"author\":{\"name\":\"Brian De Sousa\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b3add10a27821f3334ef6ea4517afa38\"},\"headline\":\"Using Node 11.7 Worker Threads with RxJS Observable\",\"datePublished\":\"2019-02-19T10:15:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/\"},\"wordCount\":1075,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"articleSection\":[\"Node.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/\",\"name\":\"Using Node 11.7 Worker Threads with RxJS Observable - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"datePublished\":\"2019-02-19T10:15:46+00:00\",\"description\":\"Interested to learn about RxJS Observable? Check our article explaining how to use worker threads to execute a task asynchronously with RxJS Observable.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Node.js\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Using Node 11.7 Worker Threads with RxJS Observable\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b3add10a27821f3334ef6ea4517afa38\",\"name\":\"Brian De Sousa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e6d9ee737fde3578595268395d83bed5675158601972fb206794255c46798404?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e6d9ee737fde3578595268395d83bed5675158601972fb206794255c46798404?s=96&d=mm&r=g\",\"caption\":\"Brian De Sousa\"},\"description\":\"Brian De Sousa is a senior software developer working in the financial industry. He has over 10 years of experience developing web applications with a variety of web technologies. He has a passion for developing solutions using the latest and greatest technologies and frameworks.\",\"sameAs\":[\"https:\/\/briandesousa1.wordpress.com\/\",\"https:\/\/www.linkedin.com\/in\/briandesousa?trk=hp-identity-name\",\"https:\/\/x.com\/briandesousa1\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/brian-de-sousa\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using Node 11.7 Worker Threads with RxJS Observable - Web Code Geeks - 2026","description":"Interested to learn about RxJS Observable? Check our article explaining how to use worker threads to execute a task asynchronously with RxJS Observable.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/","og_locale":"en_US","og_type":"article","og_title":"Using Node 11.7 Worker Threads with RxJS Observable - Web Code Geeks - 2026","og_description":"Interested to learn about RxJS Observable? Check our article explaining how to use worker threads to execute a task asynchronously with RxJS Observable.","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2019-02-19T10:15:46+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","type":"image\/jpeg"}],"author":"Brian De Sousa","twitter_card":"summary_large_image","twitter_creator":"@briandesousa1","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Brian De Sousa","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/"},"author":{"name":"Brian De Sousa","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b3add10a27821f3334ef6ea4517afa38"},"headline":"Using Node 11.7 Worker Threads with RxJS Observable","datePublished":"2019-02-19T10:15:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/"},"wordCount":1075,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","articleSection":["Node.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/","name":"Using Node 11.7 Worker Threads with RxJS Observable - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","datePublished":"2019-02-19T10:15:46+00:00","description":"Interested to learn about RxJS Observable? Check our article explaining how to use worker threads to execute a task asynchronously with RxJS Observable.","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/using-node-11-7-worker-threads-rxjs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"Node.js","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/"},{"@type":"ListItem","position":4,"name":"Using Node 11.7 Worker Threads with RxJS Observable"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b3add10a27821f3334ef6ea4517afa38","name":"Brian De Sousa","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e6d9ee737fde3578595268395d83bed5675158601972fb206794255c46798404?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e6d9ee737fde3578595268395d83bed5675158601972fb206794255c46798404?s=96&d=mm&r=g","caption":"Brian De Sousa"},"description":"Brian De Sousa is a senior software developer working in the financial industry. He has over 10 years of experience developing web applications with a variety of web technologies. He has a passion for developing solutions using the latest and greatest technologies and frameworks.","sameAs":["https:\/\/briandesousa1.wordpress.com\/","https:\/\/www.linkedin.com\/in\/briandesousa?trk=hp-identity-name","https:\/\/x.com\/briandesousa1"],"url":"https:\/\/www.webcodegeeks.com\/author\/brian-de-sousa\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/24070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/141"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=24070"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/24070\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/924"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=24070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=24070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=24070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}