Created
May 25, 2020 16:37
-
-
Save dkomanov/efb839e207fbfd4719a8270cddc4df97 to your computer and use it in GitHub Desktop.
[writing-async-app-in-scala-part-3] smartMap extension
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
def smartMap[U](f: T => U)(implicit ec: ExecutionContext): Future[U] = | |
if (future.isCompleted) { | |
if (future.value.get.isSuccess) | |
wrap(f(future.value.get.get)) | |
else | |
future.asInstanceOf[Future[U]] | |
} else { | |
future.map(f)(ec) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment