Skip to content

Instantly share code, notes, and snippets.

@RedBeard0531
Created December 19, 2017 17:26
Show Gist options
  • Save RedBeard0531/7e0895fbe73a0d13fb4e74ac854e6ce1 to your computer and use it in GitHub Desktop.
Save RedBeard0531/7e0895fbe73a0d13fb4e74ac854e6ce1 to your computer and use it in GitHub Desktop.
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