Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for worker_threads #901

Closed
haroldiedema opened this issue Jul 28, 2022 · 8 comments · Fixed by #3923
Closed

Support for worker_threads #901

haroldiedema opened this issue Jul 28, 2022 · 8 comments · Fixed by #3923
Labels
enhancement New feature or request node.js Compatibility with Node.js APIs

Comments

@haroldiedema
Copy link

What is the problem this feature will solve?

Some heavy server-side applications rely on multithreading. We run a couple of these in our company. I wanted to see if bun is a viable alternative to Node, but it seems bun doesn't support worker_threads (yet).

What is the feature you are proposing to solve the problem?

I would like to see support for the worker_threads module in bun.

What alternatives have you considered?

No response

@haroldiedema haroldiedema added the enhancement New feature or request label Jul 28, 2022
@Jarred-Sumner
Copy link
Collaborator

Bun needs to do this

I think it'd be good for Worker to be a global, like in browsers but also support importing from "worker_threads" for node compatibility

@xhyrom xhyrom added node.js Compatibility with Node.js APIs polyfill labels Jul 29, 2022
@asilvas
Copy link
Contributor

asilvas commented Aug 1, 2022

Looking forward to supporting bun in https://github.com/asilvas/ram64 !

@alexreyes
Copy link

Also looking forward to support for this!

@jimmywarting
Copy link

jimmywarting commented May 6, 2023

I suggest you impl real spec'ed web worker instead and not NodeJS specific worker.
Deno did this. and there is a highly upvoted github issue: nodejs/node#43583 to actually provide NodeJS with a spec'ed web worker.
it should be based on postMessages, EventTarget (not EventEmitter) and it should support { type: 'module' }, and support loading worker from objectURLs (like those created from dynamic code / blobs + URL.createObjectURL)

it's better to be cross-platform compatible instead.

@ivanjeremic
Copy link

I suggest you impl real spec'ed web worker instead and not NodeJS specific worker. Deno did this. and there is a highly upvoted github issue: nodejs/node#43583 to actually provide NodeJS with a spec'ed web worker. it should be based on postMessages, EventTarget (not EventEmitter) and it should support { type: 'module' }

it's better to be cross-platform compatible instead.

I agree, we are currently in a mess, I hope we all will write 1 language on the server one day and JS Server APIs are one to one the same in all runtimes.

@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Jul 18, 2023

A small update

We haven't added worker_threads support yet, but we did add Web Workers in #3645. It will be part of Bun v0.7.0.

Bun will support worker_threads along with Web Workers, but worker_threads support will come in a release shortly after 0.7 (it needs BroadcastChannel, MessagePort, customizing stdout, stderr, and a few other things so it's more complicated)

Note that we still haven't landed support for resolving blob: or data: URLs yet. We are planning to do that.

@Electroid
Copy link
Contributor

When the CI for this PR finishes, you'll be able to try it out using bun upgrade --canary. This will be released in Bun v0.7.2.

@ImLunaHey
Copy link
Contributor

Can confirm canary is working. 🙏

➜  vote git:(main) ✗ bun run test
$ vitest run --coverage
[0.06ms] ".env"
SyntaxError: Import named 'receiveMessageOnPort' not found in module 'node:worker_threads'.
➜  vote git:(main) ✗ bun upgrade --canary
[5.93s] Upgraded.

Welcome to bun's latest canary build!

Report any bugs:

    https://github.com/oven-sh/bun/issues

Changelog:

    https://github.com/oven-sh/bun/compare/53cc4df191aa823c3a5c5a2a377701439a2d3f89...main
➜  vote git:(main) ✗ bun run test        
$ vitest run --coverage
[0.04ms] ".env"
SyntaxError: Import named 'Console' not found in module 'node:console'.
error: script "test" exited with code 1 (SIGHUP)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants