Closed Menduist closed 1 year ago
lgtm but needs a round of testing with nimbus-eth2
Defects are now handled by failing the future with a new exception, similarly to other exceptions Could also leave the future running, but since the chronosStrictException will become default, not sure it's worth the trouble
Could also leave the future running, but since the chronosStrictException will become default, not sure it's worth the trouble
let's leave the future running and propagate to poll
like it was before
This is causing some regression in the libp2p CI, investigating..
Fixed the regression, I also took the opportunity to "improve" #401, since we now need a template to set the result anyway
The issue was:
proc returnResult: Future[int] {.async.} =
var result: int
result = 12
return result
was not working properly anymore, since return result
was transformed to result = result; return nil
which was not setting the correct result
The fix is:
var result {.used.}: int
template setResult(code: untyped) {.used.} =
result = code
block:
var result: int
result = 12
setResult(12)
since result is bound in the template, this will set the correct result.
And I took the opportunity to handle the implicit returns directly inside setResult:
template setResult(code: untyped) {.used.} =
when typeof(code) is void:
code
else:
result = code
LMKWYT
libp2p & nimbus tests now pass with this branch
Alternative to https://github.com/status-im/nim-chronos/pull/418 Fixes #415
This moves the error handling to the closure (instead of the
futureContinue
). In the finally, we complete withresult
in case of success. Example: