Reputation: 691
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.
Upvotes: 6
Views: 12048
Reputation: 371
In Scala 2.12 the built-in Future.unit
is the way to go. It has the benefit of being cached.
Upvotes: 25
Reputation: 23329
You can return a Future
that holds a value of Unit
def doSomething():Future[Unit] = {
TimeUnit.SECONDS.sleep(3)
println("hi")
Future.successful(())
}
Upvotes: 7