Ensures that asyncmacro2 does not raise exceptions (#172)
* Ensures that asyncmacro2 does not raise exceptions * Remove unnecessary include
This commit is contained in:
parent
075b7abf4c
commit
e5d3ecdd01
|
@ -10,8 +10,6 @@
|
|||
|
||||
{.push raises: [Defect].}
|
||||
|
||||
include "system/inclrtl"
|
||||
|
||||
import std/[os, tables, strutils, heapqueue, lists, options, nativesockets, net,
|
||||
deques]
|
||||
import ./timer
|
||||
|
@ -1073,12 +1071,8 @@ proc wait*[T](fut: Future[T], timeout = -1): Future[T] {.
|
|||
else:
|
||||
wait(fut, timeout.milliseconds())
|
||||
|
||||
{.pop.}
|
||||
|
||||
include asyncmacro2
|
||||
|
||||
{.push raises: [Defect].}
|
||||
|
||||
proc runForever*() {.raises: [Defect, CatchableError].} =
|
||||
## Begins a never ending global dispatcher poll loop.
|
||||
## Raises different exceptions depending on the platform.
|
||||
|
|
|
@ -161,7 +161,7 @@ proc processBody(node, retFutureSym: NimNode,
|
|||
proc getName(node: NimNode): string {.compileTime.} =
|
||||
case node.kind
|
||||
of nnkSym:
|
||||
return $node
|
||||
return node.strVal
|
||||
of nnkPostfix:
|
||||
return node[1].strVal
|
||||
of nnkIdent:
|
||||
|
@ -184,8 +184,7 @@ proc isInvalidReturnType(typeName: string): bool =
|
|||
|
||||
proc verifyReturnType(typeName: string) {.compileTime.} =
|
||||
if typeName.isInvalidReturnType:
|
||||
error("Expected return type of 'Future' got '$1'" %
|
||||
typeName)
|
||||
error("Expected return type of 'Future' got '" & typeName & "'")
|
||||
|
||||
macro unsupported(s: static[string]): untyped =
|
||||
error s
|
||||
|
@ -309,7 +308,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
|||
))
|
||||
|
||||
# If proc has an explicit gcsafe pragma, we add it to iterator as well.
|
||||
if prc.pragma.findChild(it.kind in {nnkSym, nnkIdent} and $it == "gcsafe") != nil:
|
||||
if prc.pragma.findChild(it.kind in {nnkSym, nnkIdent} and it.strVal == "gcsafe") != nil:
|
||||
closureIterator.addPragma(newIdentNode("gcsafe"))
|
||||
outerProcBody.add(closureIterator)
|
||||
|
||||
|
@ -335,7 +334,10 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
|||
# Add discardable pragma.
|
||||
if returnType.kind == nnkEmpty:
|
||||
# Add Future[void]
|
||||
result.params[0] = parseExpr("Future[void]")
|
||||
result.params[0] =
|
||||
newNimNode(nnkBracketExpr, prc)
|
||||
.add(newIdentNode("Future"))
|
||||
.add(newIdentNode("void"))
|
||||
if procBody.kind != nnkEmpty:
|
||||
result.body = outerProcBody
|
||||
#echo(treeRepr(result))
|
||||
|
|
Loading…
Reference in New Issue