Skip to content

Stateful event loop

Artem Starikov requested to merge stateful-event-loop into master

This MR brings in the stateful event loop, which allows sharing some state among all handlers.

To use the stateful event loop, one needs to replace Bot::event_loop with Bot::stateful_event_loop providing the initial state. In a stateful event loop, all handlers take an additional, second parameter containing the state. It's also possible to go from an EventLoop to StatefulEventLoop by calling EventLoop::into_stateful, as well as to go back by calling StatefulEventLoop::into_stateless or switch state by calling StatefulEventLoop::with_other_state.

StatefulEventLoop also provides handle_if for each handle (e.g. texttext_if) which executes the handler if the predicate returns true.

The new top-level module, state, provides Chats and Messages — in-memory state stores for common uses of state. There are also new examples on how to use them.

Closes #2 (closed).

Edited by Artem Starikov

Merge request reports