Hacker News new | ask | show | jobs
by inglor 418 days ago
> Unlike Node.js, Rust's Tokio allows us to spawn a new Task and run futures within it.

Nice article! For future reference in Node.js this would be `worker_threads` or if you want a higher level tokio like API something like https://piscinajs.dev/

This has been possible in Node.js for quite a while

--

Also for blocking I/O CPU bound parallelism I've found Rayon to be a pleasure. It has a few caveats but it leverages the Rust race condition checking well and it's very ergonomic.

I happily mix it with `tokio` in an application that is CPU bound but has to perform some async I/O (due to the SDKs it uses)

2 comments

A tokio task is not a thread
A node worker_thread is not a thread either though :]
Right at the top of the docs for worker_threads:

> The node:worker_threads module enables the use of threads that execute JavaScript in parallel.

Now that it doesn’t say “concurrent”, it says “parallel”. This implies that multiple threads are involved.

Really? The docs make it seems like it is: https://nodejs.org/api/worker_threads.html#worker-threads
> piscinajs

Lmao this wordplay made my day

> Rust race condition checking

Nit: Rust does not prevent race conditions, it prevents data races.