Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should avoid usage of Future in scala [closed]

Tags:

scala

future

Orignial Question

  1. Is there any situation we should avoid returning a Future from a class method? What is the cost of Futurizing a method?

  2. What if other methods are returning Future, should we still futurize methods if the methods only perform trivial computations to keep the interface consistency?

I would like to know what is the overhead of Futurizing a method (If there's any)?

Edit-1

What is the cost/overhead of wrapping a method into Future in Scala (if any), in the context of Java Runtime?

I guess it will at least generate more Garbage for GC, but I am not sure.

like image 831
Qingwei Avatar asked Dec 20 '25 16:12

Qingwei


1 Answers

There is no need to 'futurise' anything unless that method has asynchronous work to do, i.e. has to wait itself for futures. If the method takes too much time, the caller can always wrap the call into a Future. I would therefore conclude, don't use Future in your API until you really need it.

like image 121
0__ Avatar answered Dec 22 '25 07:12

0__



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!