Accessing value returned by scala futures

后端 未结 6 693
野趣味
野趣味 2020-12-01 01:54

I am a newbie to scala futures and I have a doubt regarding the return value of scala futures.

So, generally syntax for a scala future is

 def downl         


        
6条回答
  •  温柔的废话
    2020-12-01 02:20

    The case of Success(listInt) => I want to return the listInt and I am not able to figure out how to do that.

    The best practice is that you don't return the value. Instead you just pass the future (or a version transformed with map, flatMap, etc.) to everyone who needs this value and they can add their own onComplete.

    If you really need to return it (e.g. when implementing a legacy method), then the only thing you can do is to block (e.g. with Await.result) and you need to decide how long to await.

提交回复
热议问题