Skip to content

Instantly share code, notes, and snippets.

@dkomanov
Created May 25, 2020 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkomanov/efb839e207fbfd4719a8270cddc4df97 to your computer and use it in GitHub Desktop.
Save dkomanov/efb839e207fbfd4719a8270cddc4df97 to your computer and use it in GitHub Desktop.
[writing-async-app-in-scala-part-3] smartMap extension
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