Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[writing-async-app-in-scala-part-3] map described
def map[U](f: T => U)
(implicit ec: ExecutionContext): Future[U] = {
val promise = Promise()
if (isCompleted) // in real code this is an atomic operation + pattern matching
// even if it's completed, callback is submitted to ExecutionContext
ec.execute(() => {
f(result)
})
else
registerCallback(f)(ec)
promise.future
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment