diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-09-09 01:16:28 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-09-09 01:16:28 +0100 |
commit | dd33069d593878e0e7c073ca3ef81157e105667c (patch) | |
tree | 4f5bcec4b3ec272b4d89d34cf45bd7a7d39081a6 /lib/pure | |
parent | 6689fa68f5ee3868b128b308cb237be5c4aa5d98 (diff) | |
download | Nim-dd33069d593878e0e7c073ca3ef81157e105667c.tar.gz |
Implements getCurrentException for try in async procs. Ref #1487.
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/asyncdispatch.nim | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 1cf54b922..f3d37f9d2 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -973,7 +973,7 @@ template createCb*(retFutureSym, iteratorNameSym, #{.pop.} proc generateExceptionCheck(futSym, tryStmt, rootReceiver, fromNode: PNimrodNode): PNimrodNode {.compileTime.} = - if tryStmt.len == 1: + if tryStmt.kind == nnkNilLit: result = rootReceiver else: var exceptionChecks: seq[tuple[cond, body: PNimrodNode]] = @[] @@ -1007,8 +1007,14 @@ proc generateExceptionCheck(futSym, let elseNode = newNimNode(nnkElse, fromNode) elseNode.add newNimNode(nnkStmtList, fromNode) elseNode[0].add rootReceiver + + let ifBody = newStmtList() + ifBody.add newCall(newIdentNode("setCurrentException"), errorNode) + ifBody.add newIfStmt(exceptionChecks) + ifBody.add newCall(newIdentNode("setCurrentException"), newNilLit()) + result = newIfStmt( - (newDotExpr(futSym, newIdentNode("failed")), newIfStmt(exceptionChecks)) + (newDotExpr(futSym, newIdentNode("failed")), ifBody) ) result.add elseNode @@ -1224,6 +1230,8 @@ proc recvLine*(socket: TAsyncFD): Future[string] {.async.} = ## If the socket is disconnected in the middle of a line (before ``\r\L`` ## is read) then line will be set to ``""``. ## The partial line **will be lost**. + ## + ## **Warning**: This assumes that lines are delimited by ``\r\l``. template addNLIfEmpty(): stmt = if result.len == 0: @@ -1236,9 +1244,8 @@ proc recvLine*(socket: TAsyncFD): Future[string] {.async.} = if c.len == 0: return "" if c == "\r": - c = await recv(socket, 1, {SocketFlag.SafeDisconn, SocketFlag.Peek}) - if c.len > 0 and c == "\L": - discard await recv(socket, 1) + c = await recv(socket, 1) + assert c == "\l" addNLIfEmpty() return elif c == "\L": |