status-im / nim-chronos

Chronos - An efficient library for asynchronous programming
https://status-im.github.io/nim-chronos/docs/chronos
Apache License 2.0
353 stars 51 forks source link

AsyncEventQueue: add resetRegistration() to continue using the same r… #322

Open dbrignoli opened 1 year ago

dbrignoli commented 1 year ago

…egistration key after AsyncEventQueueFullError

With EventBus being deprecated I am checking how to move exiting code to AsyncEventQueue and was wondering if the addition of resetRegistration() (tentative proc name) would be acceptable. It could be used when tasks catch AsyncEventQueueFullError and handle/log the occurence but then continue receiving events using the same key instead of getting a new one.

dbrignoli commented 1 year ago

Mentioning @cheatfate as he authored AsyncEventQueue 😃

cheatfate commented 1 year ago

why do you need to reset? I'm not sure i understand why you need to perform unregister/register sequence, if you can just continue working/handling events. Because your procedure does not do anything helpful actually - pending events still going to be scheduled, so what the reason?

dbrignoli commented 1 year ago

@cheatfate, my understanding is that once reader.overflow is set to true it will keep raising AsyncEventQueueFullError so there is no way to "reset" a reader after an overflow. The only place where reader.overflow is set to false is upon registration.

The reset would allow to keep using the same reader (using the same key) by resetting it after handling AsyncEventQueueFullError.