r/javascript • u/Waltex • Dec 05 '25
The missing standard library for multithreading in JavaScript
https://github.com/W4G1/multithreading
146
Upvotes
r/javascript • u/Waltex • Dec 05 '25
55
u/waller87 Dec 05 '25 edited Dec 05 '25
This looks good for handling the pain of multithreading in the browser, very nice. For server side multithreaded code I’d personally consider another language altogether.
14
u/sdraje Dec 06 '25
Holy shit, this is awesome. I made some absolute garbage wrappers that I can finally throw as far as I can!
5
u/raymondQADev Dec 06 '25
Wow dude this is awesome! I don’t have a use for it right now but I’m gonna save it for later! Congrats and nice job.
1
u/Fidodo Dec 06 '25
That's awesome and I've been looking for something like this. How did you get the inline functions to work as a worker? Normally workers need their own file right? How does closure scope work with typescript? Do you need to carefully track which variables are in and out of scope to avoid errors? Can the compiler somehow contain the scope of the inline function?
3
u/Spleeeee Dec 06 '25
This looks bomb.
3
u/ironykarl Dec 05 '25
This looks pretty cool
2
u/thetrexyl Dec 05 '25
Keen on trying this out, thanks for sharing
2
u/InevitableDueByMeans Dec 06 '25
FP proved to the world that shared memory and mutation are the source of much evil.
I didn't check the actual implementation of this library and I trust it may be a very good implementation, but don't you fear that encouraging the return of these patterns in general might lead to another dark era of deadlocks and similar bugs?
2
u/PatchesMaps Dec 06 '25
Neat! I've been using workers since before they had module support so I'm very used to them but I may use this library anyway so that the code doesn't scare my coworkers as much lol 😅
2
u/Martinoqom Dec 06 '25
Does it work also in React Native?
2
u/Snoo87743 Dec 06 '25
Ive had much issues with native worker threads implementation in typescript, any time i needed it, had to deploy a new service just for that.
This looks like it works out of the box
1
u/dseg90 Dec 06 '25
This is fantastic
1
u/MICK_SWAGGA Dec 07 '25
This is awesome! Looking forward to trying it out
1
u/[deleted] Jan 02 '26
Agree
1
u/galaxxy22 Dec 06 '25
What would be a use case for this
-1
u/TheThingCreator Dec 06 '25
is this kinda like
const t1 = new Promise(res => setTimeout(() => {
...do something..
res();
}, 0));
...t2, t3, t4 etc...
then
Promise.all(t1, t2, t3, ...);