Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is non blocking and blocking future in Scala?

I am using play framework , i read that Play handles every request in non blocking way. So what is the difference between Blocking & Non Blocking Future in Scala?

Also please provide information about Future & Await.Result() method Thanks !!!

like image 584
SwwapnilShirke Avatar asked Feb 17 '16 06:02

SwwapnilShirke


1 Answers

If Await.Result() is called at any point before the Future has completed, the Future becomes blocking. If you instead use onComplete, onSuccess, onFailure, map, or flatMap (and some other methods), you are registering a callback function that will occur when the Future returns. Thus, the Future is non-blocking. Use non-blocking Futures with callbacks whenever possible.

like image 169
kliew Avatar answered Sep 19 '22 18:09

kliew