My Experiences with Concurrency While Writing an NPM Package

My Experiences with Concurrency While Writing an NPM Package

My experiences with concurrency while writing an NPM package. How to Use Every Core on your Machine using NodeJS. JavaScript and NodeJS were limited by the event loop. Code executes asynchronously, but not in true parallel fashion.

How to Use Every Core on your Machine using NodeJS

Background

You have probably used other languages that have developer-friendly ways to multitask complex jobs. Unfortunately, doing this in JavaScript has always been complicated.

For the longest time, JavaScript and NodeJS were limited by the event loop. Code executes asynchronously, but not in true parallel fashion. However, that changed with the release of worker threads in NodeJS.

After discovering this concept, I immediately want to test its full capability. Unfortunately, the existing libraries are overly complex and/or lack true parallel capabilities.

Goal

I want a package that is perfect for small projects. Something that provides a job queue without relying on databases or the filesystem while proving obvious performance benefits.

Problem

Many packages are half-baked implementation of concurrency. For example, some packages have code that look like this.

for (var i = 0; i<numberOfThreads; i++) {
  promises.push(new Promise(...))
}
Promise.all(promises)

Concurrent but fatally flawed

The above code is incorrect because it leaves out some common edge cases:

  • What happens if the pool must terminate?
  • What happens if the amount of jobs is fewer than the thread count?
  • What if one job takes significantly longer than the other?

programming nodejs javascript node

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Node-RED Module for Visual NodeJS Programming

Node-RED Module for Visual NodeJS Programming. In this article, I'm going to introduce you to a NodeJS module that allows you to create. Node-RED: A flow-based programming tool that allows you to design processes (aka flows) by wiring together microservices. Simple Node.js Express App.

Visual Node.js Programming Using Node-RED

Learn how Node-RED speeds up development compared to native Node JS. I’m going to introduce you to a Node.js module that allows you to create and deploy server-side processes by using a visual, drag and drop style interface in your web browser. The module I’m referring to is called Node-RED: A flow-based programming tool that allows you to design processes (aka flows) by wiring together microservices.

The Easiest Way to Build a Web Scraper Using JavaScript and NodeJS

A web scraper represents the tool that will help us automate the process of gathering a website’s data. Build one using JavaScript & NodeJS. The Easiest Way to Build a Web Scraper Using JavaScript and Node.js

10 Tricky JavaScript Snippets for Programming interviews

Job interviews are not entirely predictable, but we often still see commonly asked tricky questions. Let’s take a look at ten of snippet.10 Tricky JavaScript Snippets for Programming Interviews. Prepare yourself for that desired job program.

Node.js Lesson: Internals of Nodejs: LibUV

In this Node.js Lesson, we are going to talk about the internals of Nodejs. This article will guide how node js works and how it can handle async tasks. What will happen if ten requests come at once? Will it handle one request and discard the other 9? or will it create a queue and serve each one by one. We will answer all these questions in this and coming lesson. Let's start.