Ask A Question

Notifications

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.https://myip.kim/ https://birthdaywishes.onl/ https://elecpay.in/tneb/

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

Reply
Join the discussion
Create an account Log in

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

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

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