hotstuff icon indicating copy to clipboard operation
hotstuff copied to clipboard

Implement event-based contexts for view changes and timeouts

Open johningve opened this issue 2 years ago • 0 comments

This PR implements two functions, ViewContext and TimeoutContext. They return contexts that can be used for operations that should be canceled upon reaching a specific view, or when a timeout occurs.

Implementing these contexts require changes to the event loop. Specifically, we have to reintroduce asynchronous handlers, as the contexts must be able to react to new events to cancel tasks that may be running on the event loop itself. I chose to refactor the event loop handlers by adding some handler options. Currently, the only options are RunAsync and WithPriority. RunAsync makes the handler execute as part of AddEvent. WithPriority effectively turns the handler into an "observer". The idea is that handlers that don't require much time to run can use the WithPriority option to be executed before the other handlers. I am deprecating the Observer functionality in favor of the priority options.

johningve avatar Aug 19 '22 11:08 johningve