All threads / What is the point of Futures if everything is blocking?
Ask A Question


You’re not receiving notifications from this thread.

What is the point of Futures if everything is blocking?

JonathanFernas asked in Javascript

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).

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 69,840+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

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

    © 2023 GoRails, LLC. All rights reserved.