diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-04-05 20:27:42 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-04-05 20:27:42 +0100 |
commit | d0478a5637dd4f75cfd615e3ed8aa4d0a082a8c9 (patch) | |
tree | 7417e050799d97fe7727dc50e823cd2c3264a271 /lib/pure/asyncdispatch.nim | |
parent | 694fc87b1d3259c49ba61f46ef27d87552faf431 (diff) | |
download | Nim-d0478a5637dd4f75cfd615e3ed8aa4d0a082a8c9.tar.gz |
Asyncdispatch fixes.
``return`` is now transformed into a ``return nil`` in the async iterator to work around the no-yield in ``try .. except ..`` closure iterator limitation.
Diffstat (limited to 'lib/pure/asyncdispatch.nim')
-rw-r--r-- | lib/pure/asyncdispatch.nim | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 84b0ebbf8..b172f18b3 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -10,6 +10,7 @@ import os, oids, tables, strutils, macros import rawsockets +export TPort ## AsyncDispatch ## -------- @@ -18,6 +19,8 @@ import rawsockets ## On Windows IOCP is used and on other operating systems the selectors module ## is used instead. +# TODO: Discarded void PFutures need to checked for exception. + # -- Futures type @@ -764,14 +767,24 @@ template createVar(futSymName: string, asyncProc: PNimrodNode, result.add newNimNode(nnkYieldStmt).add(futSym) # -> yield future<x> valueReceiver = newDotExpr(futSym, newIdentNode("read")) # -> future<x>.read -proc processBody(node, retFutureSym: PNimrodNode): PNimrodNode {.compileTime.} = +proc processBody(node, retFutureSym: PNimrodNode, + subtypeName: string): PNimrodNode {.compileTime.} = result = node case node.kind of nnkReturnStmt: result = newNimNode(nnkStmtList) - result.add newCall(newIdentNode("complete"), retFutureSym, - if node[0].kind == nnkEmpty: newIdentNode("result") else: node[0]) - result.add newNimNode(nnkYieldStmt).add(newNilLit()) + if node[0].kind == nnkEmpty: + if subtypeName != "void": + result.add newCall(newIdentNode("complete"), retFutureSym, + newIdentNode("result")) + else: + result.add newCall(newIdentNode("complete"), retFutureSym) + else: + result.add newCall(newIdentNode("complete"), retFutureSym, + node[0].processBody(retFutureSym, subtypeName)) + + result.add newNimNode(nnkReturnStmt).add(newNilLit()) + return # Don't process the children of this return stmt of nnkCommand: if node[0].kind == nnkIdent and node[0].ident == !"await": case node[1].kind @@ -819,7 +832,7 @@ proc processBody(node, retFutureSym: PNimrodNode): PNimrodNode {.compileTime.} = else: discard for i in 0 .. <result.len: - result[i] = processBody(result[i], retFutureSym) + result[i] = processBody(result[i], retFutureSym, subtypeName) #echo(treeRepr(result)) proc getName(node: PNimrodNode): string {.compileTime.} = @@ -867,7 +880,7 @@ macro async*(prc: stmt): stmt {.immediate.} = # -> <proc_body> # -> complete(retFuture, result) var iteratorNameSym = genSym(nskIterator, $prc[0].getName & "Iter") - var procBody = prc[6].processBody(retFutureSym) + var procBody = prc[6].processBody(retFutureSym, subtypeName) if subtypeName != "void": procBody.insert(0, newNimNode(nnkVarSection).add( newIdentDefs(newIdentNode("result"), returnType[1]))) # -> var result: T |