mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-01-20 18:00:04 +00:00
Refactor utils for naming clarity
This commit is contained in:
parent
37458458de
commit
264e0dcca0
@ -14,8 +14,10 @@ import ../libp2p/protocols/secure/secure
|
||||
import ../libp2p/switch
|
||||
import ../libp2p/nameresolving/[nameresolver, mockresolver]
|
||||
|
||||
import "."/[asyncunit, errorhelpers]
|
||||
export asyncunit, errorhelpers, mockresolver
|
||||
import errorhelpers
|
||||
import utils/async_tests
|
||||
|
||||
export async_tests, errorhelpers, mockresolver
|
||||
|
||||
const
|
||||
StreamTransportTrackerName = "stream.transport"
|
||||
|
@ -34,7 +34,7 @@ import
|
||||
protocols/pubsub/rpc/messages,
|
||||
]
|
||||
import ../../libp2p/protocols/pubsub/errors as pubsub_errors
|
||||
import ../helpers, ../utils/[async, futures, async, tests]
|
||||
import ../helpers, ../utils/[futures, async_tests, xtests]
|
||||
|
||||
from ../../libp2p/protocols/pubsub/mcache import window
|
||||
|
||||
|
@ -25,8 +25,9 @@ import
|
||||
protocols/pubsub/pubsubpeer,
|
||||
protocols/pubsub/peertable,
|
||||
protocols/pubsub/rpc/messages,
|
||||
]
|
||||
import ../helpers
|
||||
],
|
||||
../utils/[futures, async_tests],
|
||||
../helpers
|
||||
|
||||
template tryPublish(
|
||||
call: untyped, require: int, wait = 10.milliseconds, timeout = 10.seconds
|
||||
|
@ -18,7 +18,7 @@ import
|
||||
discovery/discoverymngr,
|
||||
discovery/rendezvousinterface,
|
||||
]
|
||||
import ./helpers, ./asyncunit, ./utils/[async, assertions, futures]
|
||||
import ./helpers, ./utils/[futures, assertions, async_tests]
|
||||
|
||||
proc createSwitch(rdv: RendezVous = RendezVous.new()): Switch =
|
||||
SwitchBuilder
|
||||
|
@ -1,30 +0,0 @@
|
||||
import chronos/futures, stew/results, chronos
|
||||
import ./futures
|
||||
|
||||
proc toOk(future: Future[void]): Result[void, string] =
|
||||
return results.ok()
|
||||
|
||||
proc toOk[T](future: Future[T]): Result[T, string] =
|
||||
return results.ok(future.read())
|
||||
|
||||
proc toResult*[T](future: Future[T]): Result[T, string] =
|
||||
if future.cancelled():
|
||||
return results.err("Future cancelled/timed out.")
|
||||
elif future.finished():
|
||||
if not future.failed():
|
||||
return future.toOk()
|
||||
else:
|
||||
return results.err("Future finished but failed.")
|
||||
else:
|
||||
return results.err("Future still not finished.")
|
||||
|
||||
proc waitForResult*[T](
|
||||
future: Future[T], timeout = DURATION_TIMEOUT
|
||||
): Future[Result[T, string]] {.async.} =
|
||||
discard await future.withTimeout(timeout)
|
||||
return future.toResult()
|
||||
|
||||
proc reset*[T](future: Future[T]): void =
|
||||
# Likely an incomplete reset, but good enough for testing purposes (for now)
|
||||
future.internalError = nil
|
||||
future.internalState = FutureState.Pending
|
@ -1,5 +1,33 @@
|
||||
import chronos
|
||||
import chronos/futures, stew/results, chronos
|
||||
|
||||
const
|
||||
DURATION_TIMEOUT* = 1.seconds
|
||||
DURATION_TIMEOUT_EXTENDED* = 1500.milliseconds
|
||||
|
||||
proc toOk(future: Future[void]): Result[void, string] =
|
||||
return results.ok()
|
||||
|
||||
proc toOk[T](future: Future[T]): Result[T, string] =
|
||||
return results.ok(future.read())
|
||||
|
||||
proc toResult*[T](future: Future[T]): Result[T, string] =
|
||||
if future.cancelled():
|
||||
return results.err("Future cancelled/timed out.")
|
||||
elif future.finished():
|
||||
if not future.failed():
|
||||
return future.toOk()
|
||||
else:
|
||||
return results.err("Future finished but failed.")
|
||||
else:
|
||||
return results.err("Future still not finished.")
|
||||
|
||||
proc waitForResult*[T](
|
||||
future: Future[T], timeout = DURATION_TIMEOUT
|
||||
): Future[Result[T, string]] {.async.} =
|
||||
discard await future.withTimeout(timeout)
|
||||
return future.toResult()
|
||||
|
||||
proc reset*[T](future: Future[T]): void =
|
||||
# Likely an incomplete reset, but good enough for testing purposes (for now)
|
||||
future.internalError = nil
|
||||
future.internalState = FutureState.Pending
|
||||
|
Loading…
x
Reference in New Issue
Block a user