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

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

Join the discussion

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

Join 37,344+ 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.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.