* Fix cancellation behavior.
Fix some compilation warnings.
* Fix cancelAndWait() and add proper documentation.
* Add completed(Future) and done(Future) calls to check if Future[T] completed without an error.
* Add stepsAsync() and tests.
* Fix comments.
* Fix new primitive comment, to avoid usage for task switches.
* release callback memory early
this fixes a memory leak where a deleted callback may keep references
alive until the future is finished.
In particular, when using helpers like `or` which try to remove
themselves from the callback list when a dependent future is completed,
create a reference chain between all futures in the expression - in the
pathological case where one of the futures is completes only rarely (for
example a timeout or a cancellation task), the buildup will be
significant.
* Removing unnecessary asserts, and place comments instead.
* Fix `locked` flag to be more consistent.
Refactor AsyncLock to not use `result`.
Add test for `locked` flag.
* Fixes.
* Fix imports.
* Fix multiple release() without scheduler.
Add more tests.
* Fix review comments.
* small fixes
* more efficient codegen for nil check (much less code)
* release futures earlier in AsyncEvent
* release finished future earlier in AsyncQueue
* avoid searches for futures (deque variant unused / broken)
* avoid catching defects
* Fix AsyncEvent test, because of optimization.
* delete fix
* avoid seq allocs
* Keep style consistent with other code.
Refactor AsyncEvent and AsyncQueue to not use `result` keyword.
Co-authored-by: cheatfate <eugene.kabanov@status.im>
This reverts commit e45ef32b5b.
Metrics implemented this way, with a lock inside the otherwise tight
event loop are not consistent with the chronos architecture that for
good or bad uses thread local variables to avoid them - the solution
does not have rough consensus behind it, and other avenues should be
explored for this generally useful functionality.
This reverts commit d0a17d551f.
Moving CancelledError outside of the established Nim hierarchy is
not a solution that has rough consensus and has an unknown impact
on compatibility with otherwise correctly implemented cancellation
code (for example when `CatchableError` is caught, cleanup is done,
then the exception is reraised). Further, this breaks the established
convention in the Nim community that Exception should not be inherited
from, complicating compatibility with future Nim versions that may
enforce this more strongly.
This reverts commit 284d677815.
There is no rough consensus for how this should be implemented and
whether it's needed indeed - a use case that cannot be solved with
a queue or a lock/event should be identified before pursuing this
functionality.
This reverts commit baf33f04ea.
This change hides exceptions that should be handled explicitly -
asyncCheck is a debugging tool that should only be used in
exception-free situations (indeed, to fail when the operation
unexpectedly raises). There is no rough consensus behind this
change.
The cancellation process has a very complicated control flow, split over
different files and hidden by macros. These comments should help shed a
light on this madness.
* Make Future tracking optional via -d:chronosDutureTracking compilation flag.
* Stack traces is now optional, use -d:chronosStackTraces.
* Fix mistypes and add test for chronosStackTrace option.