nim-chronos
nim-chronos copied to clipboard
all API raise OSError due to lazy `getDispatcher` initialization
getDispatcher
does lazy initialization - this means it's not possible to use the chronos
API safely without introducing error handling in every call because it may raise an OSError (and thus has the raises OSError effect) - even calls that "logically" should not fail, such as setTimer
that merely adds a timer to the loop may fail on this initialization.
It would be good to be able to do all initialization during application startup such that it can happen in a "controlled" manner and that subsequent uses of the API are safe from errors of this kind.
Options discussed:
- introduce
init
and raiseDefect
fromgetDispatcher
- users must manually initialize chronos on every thread before using any of the calls which is not obvious from the API
- implement https://github.com/status-im/nim-chronos/issues/17
- risk that dispatcher gets used from different threads even though it's not adequately prepared
- inconvenient to pass dispatcher around