Futures with an error but no callback no longer raise.
This was done as a safety measure against futures which may be accidentally discarded when they have an exception leading the exception being silently forgotten. Unfortunately we will need to come up with some other solution.
This commit is contained in:
parent
e383200cf8
commit
9ea0d0c59e
1 changed files with 11 additions and 6 deletions
|
|
@ -26,12 +26,12 @@ export TPort
|
||||||
## **Note:** This module is still largely experimental.
|
## **Note:** This module is still largely experimental.
|
||||||
|
|
||||||
|
|
||||||
# TODO: Discarded void PFutures need to checked for exception.
|
# TODO: Discarded void PFutures need to be checked for exception.
|
||||||
# TODO: ``except`` statement (without `try`) does not work.
|
# TODO: ``except`` statement (without `try`) does not work.
|
||||||
# TODO: Multiple exception names in a ``except`` don't work.
|
# TODO: Multiple exception names in a ``except`` don't work.
|
||||||
# TODO: The effect system (raises: []) has trouble with my try transformation.
|
# TODO: The effect system (raises: []) has trouble with my try transformation.
|
||||||
# TODO: Can't await in a 'except' body
|
# TODO: Can't await in a 'except' body
|
||||||
|
# TODO: getCurrentException(Msg) don't work
|
||||||
|
|
||||||
# -- Futures
|
# -- Futures
|
||||||
|
|
||||||
|
|
@ -77,7 +77,8 @@ proc fail*[T](future: PFuture[T], error: ref EBase) =
|
||||||
# This is to prevent exceptions from being silently ignored when a future
|
# This is to prevent exceptions from being silently ignored when a future
|
||||||
# is discarded.
|
# is discarded.
|
||||||
# TODO: This may turn out to be a bad idea.
|
# TODO: This may turn out to be a bad idea.
|
||||||
raise error
|
# Turns out this is a bad idea.
|
||||||
|
#raise error
|
||||||
|
|
||||||
proc `callback=`*(future: PFutureBase, cb: proc () {.closure,gcsafe.}) =
|
proc `callback=`*(future: PFutureBase, cb: proc () {.closure,gcsafe.}) =
|
||||||
## Sets the callback proc to be called when the future completes.
|
## Sets the callback proc to be called when the future completes.
|
||||||
|
|
@ -775,14 +776,16 @@ proc accept*(socket: TAsyncFD): PFuture[TAsyncFD] =
|
||||||
|
|
||||||
# -- Await Macro
|
# -- Await Macro
|
||||||
|
|
||||||
template createCb*(retFutureSym, iteratorNameSym: expr): stmt {.immediate.} =
|
template createCb*(retFutureSym, iteratorNameSym,
|
||||||
|
name: expr): stmt {.immediate.} =
|
||||||
var nameIterVar = iteratorNameSym
|
var nameIterVar = iteratorNameSym
|
||||||
proc cb {.closure,gcsafe.} =
|
proc cb {.closure,gcsafe.} =
|
||||||
try:
|
try:
|
||||||
if not nameIterVar.finished:
|
if not nameIterVar.finished:
|
||||||
var next = nameIterVar()
|
var next = nameIterVar()
|
||||||
if next == nil:
|
if next == nil:
|
||||||
assert retFutureSym.finished, "Async procedure's return Future was not finished."
|
assert retFutureSym.finished, "Async procedure's (" &
|
||||||
|
name & ") return Future was not finished."
|
||||||
else:
|
else:
|
||||||
next.callback = cb
|
next.callback = cb
|
||||||
except:
|
except:
|
||||||
|
|
@ -987,7 +990,8 @@ macro async*(prc: stmt): stmt {.immediate.} =
|
||||||
|
|
||||||
# -> createCb(retFuture)
|
# -> createCb(retFuture)
|
||||||
var cbName = newIdentNode("cb")
|
var cbName = newIdentNode("cb")
|
||||||
var procCb = newCall("createCb", retFutureSym, iteratorNameSym)
|
var procCb = newCall("createCb", retFutureSym, iteratorNameSym,
|
||||||
|
newStrLitNode(prc[0].getName))
|
||||||
outerProcBody.add procCb
|
outerProcBody.add procCb
|
||||||
|
|
||||||
# -> return retFuture
|
# -> return retFuture
|
||||||
|
|
@ -1010,6 +1014,7 @@ macro async*(prc: stmt): stmt {.immediate.} =
|
||||||
result[6] = outerProcBody
|
result[6] = outerProcBody
|
||||||
|
|
||||||
#echo(treeRepr(result))
|
#echo(treeRepr(result))
|
||||||
|
#if prc[0].getName == "routeReq":
|
||||||
#echo(toStrLit(result))
|
#echo(toStrLit(result))
|
||||||
|
|
||||||
proc recvLine*(socket: TAsyncFD): PFuture[string] {.async.} =
|
proc recvLine*(socket: TAsyncFD): PFuture[string] {.async.} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue