From d0478a5637dd4f75cfd615e3ed8aa4d0a082a8c9 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Sat, 5 Apr 2014 20:27:42 +0100 Subject: 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. --- lib/pure/asyncdispatch.nim | 25 +++++++++++++++++++------ lib/pure/httpclient.nim | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'lib') 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 valueReceiver = newDotExpr(futSym, newIdentNode("read")) # -> future.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 .. # -> 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 diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index fea045221..415775583 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -430,7 +430,7 @@ proc generateHeaders(r: TURL, httpMethod: THttpMethod, add(result, "\c\L") type - PAsyncHttpClient = ref object + PAsyncHttpClient* = ref object socket: PAsyncSocket connected: bool currentURL: TURL ## Where we are currently connected. -- cgit 1.4.1-2-gfad0