Add an API to WIOService to cancel scheduled tasks
As mentioned in #5648, WIOService::stop() blocks until all tasks, running or scheduled to run, are executed. Since there is no API to cancel scheduled tasks, WServer::stop() may get blocked due to scheduled tasks. If a scheduled task is to be run after a long period of time, the application becomes useless since the server is stopped before the IO service is stopped in WServer::stop().
IMO, an API such as WIOService::cancelScheduledTasks() should be added to WIOService and called in WServer::stop() before stopping the IO service.
Updated by Wim Dumon almost 6 years ago
- Assignee set to Roel Standaert
That would probably be a useful addition.
We noted however that deadline_timers are not thread safe, so canceling them will need to be done with proper care in Wt's multithreaded architecture.
This splits the problem in two parts:
- create timers so that they can be canceled (proper use of strands seem to allow for this); in that respect it's probably a good idea to have the schedule call return an object that allows cancelation
- keep track of all active timers, so that cancelScheduledTasks() can be implemented