mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-15 11:53:12 +00:00
With this fix in, there is no need to use the asynctest update that sets longer defaults for eventually, so downgrade asynctest
45 lines
1.4 KiB
Nim
45 lines
1.4 KiB
Nim
import helpers/multisetup
|
|
import helpers/trackers
|
|
import helpers/templeveldb
|
|
import std/times
|
|
import std/sequtils, chronos
|
|
|
|
import ./asynctest
|
|
|
|
export multisetup, trackers, templeveldb
|
|
|
|
### taken from libp2p errorhelpers.nim
|
|
proc allFuturesThrowing*(args: varargs[FutureBase]): Future[void] =
|
|
# This proc is only meant for use in tests / not suitable for general use.
|
|
# - Swallowing errors arbitrarily instead of aggregating them is bad design
|
|
# - It raises `CatchableError` instead of the union of the `futs` errors,
|
|
# inflating the caller's `raises` list unnecessarily. `macro` could fix it
|
|
let futs = @args
|
|
(
|
|
proc() {.async: (raises: [CatchableError]).} =
|
|
await allFutures(futs)
|
|
var firstErr: ref CatchableError
|
|
for fut in futs:
|
|
if fut.failed:
|
|
let err = fut.error()
|
|
if err of CancelledError:
|
|
raise err
|
|
if firstErr == nil:
|
|
firstErr = err
|
|
if firstErr != nil:
|
|
raise firstErr
|
|
)()
|
|
|
|
proc allFuturesThrowing*[T](futs: varargs[Future[T]]): Future[void] =
|
|
allFuturesThrowing(futs.mapIt(FutureBase(it)))
|
|
|
|
proc allFuturesThrowing*[T, E]( # https://github.com/nim-lang/Nim/issues/23432
|
|
futs: varargs[InternalRaisesFuture[T, E]]
|
|
): Future[void] =
|
|
allFuturesThrowing(futs.mapIt(FutureBase(it)))
|
|
|
|
template eventuallySafe*(
|
|
expression: untyped, timeout = 5000, pollInterval = 1000
|
|
): bool =
|
|
eventually(expression, timeout, pollInterval)
|