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

32
faststreams/multisync.nim Normal file
View file

@ -0,0 +1,32 @@
import
stew/shims/macros,
async_backend, input_stream, output_stream
macro fsMultiSync*(body: untyped) =
# We will produce an identical copy of the annotated proc,
# but taking async parameters and having the async pragma.
var
asyncProcBody = copy body
asyncProcParams = asyncBody[3]
asyncProcBody.addPragma(bindSym"async")
# The return types becomes Future[T]
if asyncProcParams[0].kind == nnkEmpty
asyncProcParams[0] = newBracketExpr(ident"Future", ident"void")
else:
asyncProcParams[0] = newBracketExpr(ident"Future", asyncProcParams[0])
# We replace all stream inputs with their async counterparts
for i in 1 ..< asyncProcParams.len:
let paramsDef = asyncProcParams[i]
let typ = paramsDef[^2]
if sameType(typ, bindSym"InputStream"):
paramsDef[^2] = bindSym "AsyncInputStream"
elif sameType(typ, bindSym"OutputStream"):
paramsDef[^2] = bindSym "AsyncOutputStream"
result = newStmtList(body, asyncBody)
if defined(debugSupportAsync):
echo result.repr