Initial work on pipelines

This commit is contained in:
Zahary Karadjov 2020-04-13 21:59:34 +03:00
commit 69fc4e24ee
No known key found for this signature in database
GPG key ID: C8936F8A3073D609
11 changed files with 525 additions and 72 deletions

View file

@ -0,0 +1,31 @@
const
faststreams_async_backend {.strdefine.} = "chronos"
when faststreams_async_backend == "chronos":
import chronos # import chronos/[asyncfutures2, asyncmacro2]
export chronos # export asyncfutures2, asyncmacro2
template faststreamsAwait*(f: Future): untyped =
await f
elif faststreams_async_backend in ["std", "asyncdispatch"]:
import std/[asyncfutures, asyncmacro]
export asyncfutures, asyncmacro
template faststreamsAwait*(awaited: Future[T]): untyped =
# TODO revisit after https://github.com/nim-lang/Nim/pull/12085/ is merged
let f = awaited
yield f
if not isNil(f.error):
raise f.error
f.read
else:
{.fatal: "Unrecognized network backend: " & faststreams_async_backend.}
template raiseFaststreamsError*(errMsg: string, body: untyped) =
try:
body
except CatchableError as err:
raise newException(IOError, errMsg, err)