diff --git a/chronos/asyncfutures2.nim b/chronos/asyncfutures2.nim index c88e568..73e0bd1 100644 --- a/chronos/asyncfutures2.nim +++ b/chronos/asyncfutures2.nim @@ -143,18 +143,18 @@ proc remove(callbacks: var Deque[AsyncCallback], item: AsyncCallback) = proc complete*[T](future: Future[T], val: T) = ## Completes ``future`` with value ``val``. - #assert(not future.finished, "Future already finished, cannot finish twice.") + #doAssert(not future.finished, "Future already finished, cannot finish twice.") checkFinished(future) - assert(future.error == nil) + doAssert(future.error == nil) future.value = val future.finished = true future.callbacks.call() proc complete*(future: Future[void]) = ## Completes a void ``future``. - #assert(not future.finished, "Future already finished, cannot finish twice.") + #doAssert(not future.finished, "Future already finished, cannot finish twice.") checkFinished(future) - assert(future.error == nil) + doAssert(future.error == nil) future.finished = true future.callbacks.call() @@ -162,7 +162,7 @@ proc complete*[T](future: FutureVar[T]) = ## Completes a ``FutureVar``. template fut: untyped = Future[T](future) checkFinished(fut) - assert(fut.error == nil) + doAssert(fut.error == nil) fut.finished = true fut.callbacks.call() @@ -172,14 +172,14 @@ proc complete*[T](future: FutureVar[T], val: T) = ## Any previously stored value will be overwritten. template fut: untyped = Future[T](future) checkFinished(fut) - assert(fut.error.isNil()) + doAssert(fut.error.isNil()) fut.finished = true fut.value = val fut.callbacks.call() proc fail*[T](future: Future[T], error: ref Exception) = ## Completes ``future`` with ``error``. - #assert(not future.finished, "Future already finished, cannot finish twice.") + #doAssert(not future.finished, "Future already finished, cannot finish twice.") checkFinished(future) future.finished = true future.error = error @@ -198,7 +198,7 @@ proc addCallback*(future: FutureBase, cb: CallbackFunc, udata: pointer = nil) = ## Adds the callbacks proc to be called when the future completes. ## ## If future has already completed then ``cb`` will be called immediately. - assert cb != nil + doAssert cb != nil if future.finished: # ZAH: it seems that the Future needs to know its associated Dispatcher callSoon(cb, udata) @@ -214,7 +214,7 @@ proc addCallback*[T](future: Future[T], cb: CallbackFunc) = proc removeCallback*(future: FutureBase, cb: CallbackFunc, udata: pointer = nil) = - assert cb != nil + doAssert cb != nil let acb = AsyncCallback(function: cb, udata: udata) future.callbacks.remove acb @@ -363,7 +363,7 @@ proc asyncCheck*[T](future: Future[T]) = ## finished with an error. ## ## This should be used instead of ``discard`` to discard void futures. - assert(not future.isNil, "Future is nil") + doAssert(not future.isNil, "Future is nil") proc cb(data: pointer) = if future.failed: injectStacktrace(future) diff --git a/chronos/asyncloop.nim b/chronos/asyncloop.nim index e79f74b..1eeed64 100644 --- a/chronos/asyncloop.nim +++ b/chronos/asyncloop.nim @@ -290,7 +290,7 @@ when defined(windows) or defined(nimdoc): proc setGlobalDispatcher*(disp: PDispatcher) = ## Set current thread's dispatcher instance to ``disp``. if not gDisp.isNil: - assert gDisp.callbacks.len == 0 + doAssert gDisp.callbacks.len == 0 gDisp = disp initCallSoonProc() @@ -465,7 +465,7 @@ else: proc setGlobalDispatcher*(disp: PDispatcher) = ## Set current thread's dispatcher instance to ``disp``. if not gDisp.isNil: - assert gDisp.callbacks.len == 0 + doAssert gDisp.callbacks.len == 0 gDisp = disp initCallSoonProc() @@ -746,7 +746,7 @@ include asyncmacro2 proc callSoon(cbproc: CallbackFunc, data: pointer = nil) = ## Schedule `cbproc` to be called as soon as possible. ## The callback is called when control returns to the event loop. - assert cbproc != nil + doAssert cbproc != nil let acb = AsyncCallback(function: cbproc, udata: data) getGlobalDispatcher().callbacks.addLast(acb) diff --git a/chronos/transports/common.nim b/chronos/transports/common.nim index 44f407a..e55ac50 100644 --- a/chronos/transports/common.nim +++ b/chronos/transports/common.nim @@ -421,7 +421,7 @@ proc resolveTAddress*(address: string, port: Port, ## ## If hostname address is detected, then network address translation via DNS ## will be performed. - assert(family in {AddressFamily.IPv4, AddressFamily.IPv6}) + doAssert(family in {AddressFamily.IPv4, AddressFamily.IPv6}) result = newSeq[TransportAddress]() var domain = if family == AddressFamily.IPv4: Domain.AF_INET else: diff --git a/chronos/transports/datagram.nim b/chronos/transports/datagram.nim index f983a2d..cb056f7 100644 --- a/chronos/transports/datagram.nim +++ b/chronos/transports/datagram.nim @@ -198,9 +198,9 @@ when defined(windows): child: DatagramTransport, bufferSize: int): DatagramTransport = var localSock: AsyncFD - assert(remote.family == local.family) - assert(not isNil(cbproc)) - assert(remote.family in {AddressFamily.IPv4, AddressFamily.IPv6}) + doAssert(remote.family == local.family) + doAssert(not isNil(cbproc)) + doAssert(remote.family in {AddressFamily.IPv4, AddressFamily.IPv6}) if isNil(child): result = DatagramTransport() @@ -376,8 +376,8 @@ else: child: DatagramTransport = nil, bufferSize: int): DatagramTransport = var localSock: AsyncFD - assert(remote.family == local.family) - assert(not isNil(cbproc)) + doAssert(remote.family == local.family) + doAssert(not isNil(cbproc)) if isNil(child): result = DatagramTransport() diff --git a/tests/teststream.nim b/tests/teststream.nim index 255ded5..217c7ab 100644 --- a/tests/teststream.nim +++ b/tests/teststream.nim @@ -148,7 +148,7 @@ proc swarmWorker1(address: TransportAddress): Future[int] {.async.} = for i in 0..