mirror of
https://github.com/logos-storage/nim-chronos.git
synced 2026-01-07 16:03:09 +00:00
avoid warning in noCancel with non-raising future (#540)
This commit is contained in:
parent
52b02b9977
commit
1ff81c60ea
@ -1031,19 +1031,24 @@ proc noCancel*[F: SomeFuture](future: F): auto = # async: (raw: true, raises: as
|
|||||||
let retFuture = newFuture[F.T]("chronos.noCancel(T)",
|
let retFuture = newFuture[F.T]("chronos.noCancel(T)",
|
||||||
{FutureFlag.OwnCancelSchedule})
|
{FutureFlag.OwnCancelSchedule})
|
||||||
template completeFuture() =
|
template completeFuture() =
|
||||||
|
const canFail = when declared(InternalRaisesFutureRaises):
|
||||||
|
InternalRaisesFutureRaises isnot void
|
||||||
|
else:
|
||||||
|
true
|
||||||
|
|
||||||
if future.completed():
|
if future.completed():
|
||||||
when F.T is void:
|
when F.T is void:
|
||||||
retFuture.complete()
|
retFuture.complete()
|
||||||
else:
|
else:
|
||||||
retFuture.complete(future.value)
|
retFuture.complete(future.value)
|
||||||
elif future.failed():
|
|
||||||
when F is Future:
|
|
||||||
retFuture.fail(future.error, warn = false)
|
|
||||||
when declared(InternalRaisesFutureRaises):
|
|
||||||
when InternalRaisesFutureRaises isnot void:
|
|
||||||
retFuture.fail(future.error, warn = false)
|
|
||||||
else:
|
else:
|
||||||
raiseAssert("Unexpected future state [" & $future.state & "]")
|
when canFail: # Avoid calling `failed` on non-failing raises futures
|
||||||
|
if future.failed():
|
||||||
|
retFuture.fail(future.error, warn = false)
|
||||||
|
else:
|
||||||
|
raiseAssert("Unexpected future state [" & $future.state & "]")
|
||||||
|
else:
|
||||||
|
raiseAssert("Unexpected future state [" & $future.state & "]")
|
||||||
|
|
||||||
proc continuation(udata: pointer) {.gcsafe.} =
|
proc continuation(udata: pointer) {.gcsafe.} =
|
||||||
completeFuture()
|
completeFuture()
|
||||||
|
|||||||
@ -519,7 +519,7 @@ suite "Exceptions tracking":
|
|||||||
|
|
||||||
noraises()
|
noraises()
|
||||||
|
|
||||||
test "Nocancel errors":
|
test "Nocancel errors with raises":
|
||||||
proc testit {.async: (raises: [ValueError, CancelledError]).} =
|
proc testit {.async: (raises: [ValueError, CancelledError]).} =
|
||||||
await sleepAsync(5.milliseconds)
|
await sleepAsync(5.milliseconds)
|
||||||
raise (ref ValueError)()
|
raise (ref ValueError)()
|
||||||
@ -535,6 +535,36 @@ suite "Exceptions tracking":
|
|||||||
|
|
||||||
noraises()
|
noraises()
|
||||||
|
|
||||||
|
test "Nocancel with no errors":
|
||||||
|
proc testit {.async: (raises: [CancelledError]).} =
|
||||||
|
await sleepAsync(5.milliseconds)
|
||||||
|
|
||||||
|
proc test {.async: (raises: []).} =
|
||||||
|
await noCancel testit()
|
||||||
|
|
||||||
|
proc noraises() {.raises: [].} =
|
||||||
|
let f = test()
|
||||||
|
waitFor(f.cancelAndWait())
|
||||||
|
waitFor(f)
|
||||||
|
|
||||||
|
noraises()
|
||||||
|
|
||||||
|
test "Nocancel errors without raises":
|
||||||
|
proc testit {.async.} =
|
||||||
|
await sleepAsync(5.milliseconds)
|
||||||
|
raise (ref ValueError)()
|
||||||
|
|
||||||
|
proc test {.async.} =
|
||||||
|
await noCancel testit()
|
||||||
|
|
||||||
|
proc noraises() =
|
||||||
|
expect(ValueError):
|
||||||
|
let f = test()
|
||||||
|
waitFor(f.cancelAndWait())
|
||||||
|
waitFor(f)
|
||||||
|
|
||||||
|
noraises()
|
||||||
|
|
||||||
test "Defect on wrong exception type at runtime":
|
test "Defect on wrong exception type at runtime":
|
||||||
{.push warning[User]: off}
|
{.push warning[User]: off}
|
||||||
let f = InternalRaisesFuture[void, (ValueError,)]()
|
let f = InternalRaisesFuture[void, (ValueError,)]()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user