Address review comments; Add documentation; Shared buffering mechanism for input and output streams
This commit is contained in:
parent
caab5c917f
commit
b24300bd3f
24 changed files with 2396 additions and 1060 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue