Address review comments; Add documentation; Shared buffering mechanism for input and output streams

This commit is contained in:
Zahary Karadjov 2020-04-29 21:19:18 +03:00
commit b24300bd3f
No known key found for this signature in database
GPG key ID: C8936F8A3073D609
24 changed files with 2396 additions and 1060 deletions

View file

@ -1,18 +1,29 @@
const
faststreams_async_backend {.strdefine.} = "chronos"
when faststreams_async_backend == "chronos":
import chronos # import chronos/[asyncfutures2, asyncmacro2]
export chronos # export asyncfutures2, asyncmacro2
type
CloseBehavior* = enum
waitAsyncClose
dontWaitAsyncClose
template faststreamsAwait*(f: Future): untyped =
when faststreams_async_backend == "chronos":
import
chronos
export
chronos
template fsAwait*(f: Future): untyped =
await f
elif faststreams_async_backend in ["std", "asyncdispatch"]:
import std/[asyncfutures, asyncmacro]
export asyncfutures, asyncmacro
import
std/[asyncfutures, asyncmacro]
export
asyncfutures, asyncmacro
template faststreamsAwait*(awaited: Future[T]): untyped =
template fsAwait*(awaited: Future[T]): untyped =
# TODO revisit after https://github.com/nim-lang/Nim/pull/12085/ is merged
let f = awaited
yield f
@ -23,9 +34,15 @@ elif faststreams_async_backend in ["std", "asyncdispatch"]:
else:
{.fatal: "Unrecognized network backend: " & faststreams_async_backend.}
template raiseFaststreamsError*(errMsg: string, body: untyped) =
template fsTranslateErrors*(errMsg: string, body: untyped) =
try:
body
except CatchableError as err:
raise newException(IOError, errMsg, err)
except Exception as err:
if err[] of Defect:
raise (ref Defect)(err)
else:
raise newException(IOError, errMsg, err)
template noAwait*(expr: untyped): untyped =
expr