50 Experience
0 Lessons Completed
0 Questions Solved


Posted in What is the point of Futures if everything is blocking?

I come from a JS background so bear with me.

The biggest thing about Node is that, although it’s single threaded, you have the event loop and async IO, so promises just make so much sense.

Let’s say you have a web app, you send a query to the DB, then do something with it, then maybe read some other stuff and ultimately return something. While you’re waiting for the IO you can start/process other requests in the meantime.

In Java you have futures and I guess DeferredResult (Spring) which can help make it similar to node. However, any Hibernate calls will be blocking, any IO you do is blocking, etc. unless you do it in a separate thread (but then that defies the point of futures IMO since you’re just spinning more threads).

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.