The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →JavaScript does not automatically run ordinary code on multiple threads. To run CPU-heavy work in parallel, use a browser Worker or Node.js worker_threads, depending on where your code runs. The worker does the computation in a separate context and sends results back; async/await and promises alone do not make CPU-bound JavaScript execute in parallel.
What “multi-threading” means in JavaScript
JavaScript offers different worker APIs in browsers and Node.js. Both let JavaScript work run separately from the code that created the worker, but they are not the same API and their surrounding environments differ. In a browser, Web Workers run outside the page’s main execution context; in Node.js, the worker_threads module can execute JavaScript in parallel. See the MDN Web Workers guide and Node.js worker_threads documentation.
Asynchronous work is not the same as parallel CPU work
Promises, async/await, and asynchronous network or file operations can let a program make progress without waiting synchronously for each operation. They do not, by themselves, move a CPU-intensive JavaScript calculation to another thread. For Node.js I/O-heavy workloads, the Node.js documentation says its built-in asynchronous I/O is more efficient than workers; its worker guidance is aimed at CPU-intensive JavaScript.
Which JavaScript worker approach should you choose?
| Situation | Mechanism | Tradeoff |
|---|---|---|
| CPU-heavy work in a browser that should not block page interaction | Dedicated Web Worker | Runs in a separate context and returns results through messages; it cannot directly manipulate the page DOM. |
| Several same-origin browser contexts need to use one worker | Shared Web Worker | Clients communicate through a port, so coordinating clients and worker lifetime is part of the design. |
| CPU-heavy JavaScript in Node.js | node:worker_threads |
Allows parallel execution, but worker lifecycle, communication, and scheduling have costs. |
| I/O-heavy work in Node.js | Built-in asynchronous I/O | Node.js recommends this over workers for I/O-intensive work. |
Browser workers and their communication model are described in MDN’s Web Workers guide. Node.js’s CPU-versus-I/O guidance is in its worker_threads documentation.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
How to run CPU-heavy work in a browser
A dedicated worker is a useful starting point when a calculation would otherwise occupy the page’s main thread. Put the computation in a worker script, send it input with postMessage(), and handle the returned message in the page. The worker has its own global scope: it can perform the calculation and message the page, but the page must apply any DOM updates.
1. Create the worker script
Save this as sum-worker.js alongside the page’s JavaScript file:
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
self.onmessage = (event) => {
const total = event.data.numbers.reduce((sum, value) => sum + value, 0);
self.postMessage({ total });
};
2. Start the worker and update the page from the main script
This example assumes the page has an element with the ID result:
const worker = new Worker('./sum-worker.js');
worker.onmessage = (event) => {
document.querySelector('#result').textContent = event.data.total;
};
worker.postMessage({ numbers: [10, 20, 30] });
The worker returns the result as a message; the page’s main script updates the DOM. For worker setup, messaging, and shared-worker behavior, see MDN’s Web Workers guide.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsRank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
How to run CPU-heavy work in Node.js
In Node.js, import Worker from node:worker_threads. The example below uses CommonJS and assumes main.js and sum-worker.js are in the same directory. The worker performs one calculation, returns its result, and the main thread handles completion.
Worker script: sum-worker.js
const { parentPort } = require('node:worker_threads');
parentPort.on('message', ({ numbers }) => {
const total = numbers.reduce((sum, value) => sum + value, 0);
parentPort.postMessage({ total });
});
Main script: main.js
const path = require('node:path');
const { Worker } = require('node:worker_threads');
const worker = new Worker(path.join(__dirname, 'sum-worker.js'));
worker.on('message', ({ total }) => {
console.log('Total:', total);
});
worker.on('error', (error) => {
console.error('Worker failed:', error);
});
worker.on('exit', (code) => {
if (code !== 0) {
console.error(`Worker stopped with exit code ${code}`);
}
});
worker.postMessage({ numbers: [10, 20, 30] });
Run the main script with node main.js. For recurring CPU jobs, avoid creating a new worker for every small task: Node.js warns that worker creation overhead can exceed the benefit and recommends using a worker pool. Consult the Node.js worker_threads documentation for API details and lifecycle guidance.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
How should data move between the main context and a worker?
Choose the simplest data-passing method that fits the workload. Ordinary messaging is usually the easiest design to reason about. For large data, a transferable buffer can avoid copying its underlying memory, while shared memory can avoid message-based handoffs at the cost of synchronization work.
Message data: simpler ownership
When data is sent in a message, it is passed between contexts using the platform’s message mechanism. This is a good default for inputs and results that do not require shared, simultaneous access. With large payloads, copying can add overhead.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Transfer an ArrayBuffer when ownership can move
A transferable ArrayBuffer can be handed to another context without copying the underlying buffer. The tradeoff is ownership: after transfer, the sender can no longer use that buffer. Use this when the receiving worker should take over the data rather than share it. See MDN’s worker guide.
Use SharedArrayBuffer only when shared access is necessary
A SharedArrayBuffer lets contexts access the same memory, but shared access means your code must coordinate how it reads and writes that memory. In browsers, availability is subject to security requirements; do not assume it is defined in every page or execution context. MDN documents the object and browser security context in its SharedArrayBuffer reference.
When do you need Atomics?
When multiple workers can access shared memory, unsynchronized reads and writes can make results unreliable. The Atomics APIs provide atomic operations for coordinating access to shared data. They add complexity, so use them with shared memory rather than as a default replacement for ordinary message passing. See MDN’s Atomics reference.
Atomics.wait() can block while waiting, and it is not available in contexts such as the browser main thread. Avoid designs that depend on blocking the page’s main thread to coordinate a worker; use messaging or an appropriate non-blocking coordination pattern instead. The constraints are documented in MDN’s Atomics reference.
How to decide whether a worker is worth using
- Identify the bottleneck. Workers are for CPU-intensive JavaScript, not a general way to speed up asynchronous I/O.
- Consider the job size and frequency. A worker has setup and communication costs. For repeated Node.js CPU jobs, reuse workers through a pool rather than spawning one per task.
- Start with messages. Prefer message passing unless profiling or workload design gives you a concrete reason to transfer buffers or share memory.
- Keep ownership clear. If transferring a buffer, ensure the sender no longer needs it. If sharing memory, define how concurrent access is coordinated.
- Keep browser UI work on the page. Have a Web Worker return data, then let the page’s main script update the DOM.
Node.js’s guidance on CPU-bound work and worker pools is available in the worker_threads documentation; browser context and communication constraints are covered by MDN’s Web Workers guide.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

