-
i found the If I add event handlers dynamically, will there be any concurrency issues (I don't really see locks being used). void DelEvent(const std::string& type) {
eventHandlers.erase(type);
} (But |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @Crazyokd, This library is designed for single-threaded use with asynchronous programming. Essentially, you have boost::io_context, which is a task queue where tasks are run in the thread that calls io_context::run()—usually the main thread. With this in mind, the method Client::OnEvent should run in the same thread where the handlers are executed, i.e., the thread running io_context::run(). This shouldn't be a problem. Since the application is event-based, if you want to dynamically add or remove an event handler (even though only removal is currently possible), you'll likely do so inside an event handler that runs in the io_context thread. However, if you need to call the Client::OnEvent method from a different thread, you can use boost::io_context::post to schedule its execution in the io_context thread:
The feature you propose—removing a single handler for an event—can indeed be useful, but it requires the library to return a handle for the callback, allowing you to remove the callback using the handle. I'm going to create a GitHub issue for this. |
Beta Was this translation helpful? Give feedback.
Hi @Crazyokd,
This library is designed for single-threaded use with asynchronous programming. Essentially, you have boost::io_context, which is a task queue where tasks are run in the thread that calls io_context::run()—usually the main thread.
With this in mind, the method Client::OnEvent should run in the same thread where the handlers are executed, i.e., the thread running io_context::run().
This shouldn't be a problem. Since the application is event-based, if you want to dynamically add or remove an event handler (even though only removal is currently possible), you'll likely do so inside an event handler that runs in the io_context thread.
However, if you need to call the Client::OnE…