-
-
Save jlupien/8441914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Doesn't compile. Good. | |
def futureInt(): Future[Int] = Future.value(Future.value(1)) | |
// Compiles. Not good. Caller cannot wait on completion of nested future. | |
def futureUnit(): Future[Unit] = Future.value(Future.value(())) | |
// Also compiles. Nice convenience, but not worth the cost of the issues | |
// it might cause (as above), right? | |
def futureUnit(): Future[Unit] = Future.value(1) | |
// Maybe you could argue Future[Unit] is weird (or Unit in general is bad | |
// because side effects. But is it really avoidable? | |
// Example use case of Future[Unit]: | |
// https://github.com/twitter/util/blob/master/util-core/src/main/scala/com/twitter/util/Closable.scala | |
// I believe this shouldn't compile. Is scala 2.9.x? | |
def futureUnit(): Future[Unit] = Future.value[Int](1) | |
// You're right. So I guess the problem boils down to the fact that this compiles: | |
Future.value[Unit](1) | |
Future.value[Unit](Future.value(())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment