Created
December 19, 2017 17:26
-
-
Save RedBeard0531/7e0895fbe73a0d13fb4e74ac854e6ce1 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
import asyncdispatch | |
proc unwrap[T](outer: Future[Future[T]]): Future[T] = | |
result = newFuture[T]() | |
let res = result | |
outer.addCallback do: | |
# TODO try/catch to handle errors | |
outer.read().addCallback do (inner: Future[T]): | |
res.complete(inner.read()) | |
proc addDoubleWrapped*(a, b: Future[Future[int]]): Future[int] {.async.} = | |
return await(a.unwrap) + await(b.unwrap) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment