Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a way to return Future[Unit]?

Tags:

scala

I have a method returning Unit originally. After changing returned type to Future[Unit], I can't find out a way to change the method body. The least line is a method call.

like image 926
TeeKai Avatar asked Jun 29 '16 18:06

TeeKai


2 Answers

In Scala 2.12 the built-in Future.unit is the way to go. It has the benefit of being cached.

like image 59
Ali H. Avatar answered Jan 03 '23 15:01

Ali H.


You can return a Future that holds a value of Unit

def doSomething():Future[Unit] = {
  TimeUnit.SECONDS.sleep(3)
  println("hi")
  Future.successful(())
}
like image 44
Sleiman Jneidi Avatar answered Jan 03 '23 16:01

Sleiman Jneidi