This GitHub repo is the companion to ARTICLE.md: a short article plus runnable examples for Promises, Web Workers, Comlink, SharedArrayBuffer, workerpool, and Piscina.
Clone the repo, open an example folder, and run it while you read.
| # | Project | What it shows | Runtime |
|---|---|---|---|
| 01 | examples/01-main-thread-freeze |
Heavy loop wrapped in async still freezes the UI |
Browser |
| 02 | examples/02-raw-web-worker |
Same work via postMessage stays responsive |
Browser |
| 03 | examples/03-comlink-worker |
RPC-style API with Comlink (wrap / expose) |
Browser |
| 04 | examples/04-shared-array-buffer |
Shared memory + COOP/COEP headers | Browser |
| 05 | examples/05-workerpool |
Job queue across a pool of workers | Browser |
| 06 | examples/06-piscina-node |
Node.js worker_threads pool with Piscina |
Node |
git clone git@github.com:mrajaeim/Advanced-JS-Execution.git
cd Advanced-JS-ExecutionEach browser example uses Vite:
cd examples/02-raw-web-worker
npm install
npm run devNode example:
cd examples/06-piscina-node
npm install
npm start- Node.js 18+
- A modern Chromium-based browser for SharedArrayBuffer (example 04 needs cross-origin isolation; Vite already sets the headers)
Read the full write-up: Why Promises Do Not Free Your UI (and When Web Workers Do)
Call stack, microtasks/macrotasks, and the event loop: Why Your JavaScript Runs in the Wrong Order