We have many timers in our CC code. For example, editor activated event.
The first thing we know is that we don't directly response to those timers, because they happens too often. For example, if user open several editors in the same time, we may receive many such events, but what we are interest in is the last event. To implement this, we have a delay timer for the editor activated event.
We have many other timers, such as editor content changed, mouse position moved, editor closed, project loaded... And you can see that we have a lot of timers, which do quite similar things, they just start a delayed timer, if a similar event happens again(such as a new editor is activated again), then we just restart the timer gain, and all the actual operation is done in the timer event handler. This is the way much similar like the mouse dwell event, we only response to stable events, and thus have better performance.
Events are related, I mean if we first get a mouse position changed event, and when its delayed timer is running, we may received the new editor opened events, at this time, we should cancel the job associated with the mouse position changed event, since we have a new editor opened, and the mouse position is invalid for the new editor. In this situation, we should just sweep the job for mouse position changed event. There are a lot of similar cases of such event relationship.
Idea: I think we need a unified way to implement a TaskQueue, it may have such features:
- when an event happens, we register a new job, the job may run immediately, or we should run the job in a worker thread pool
- when an event happens, we register a new job, but a timer is started
- always keep the last same kind of event, such as editor active event, this means a new same event will cancel a same job
- event may have relations, so an important event may sweep all the previous jobs
- when the timer reached, the job should be run
- when there is not jobs in the queue, the timer may stopped
Are there some code we can directly use?EDIT:
I think not the native CC, but other CC such as CC for Fortran, Clang CC may benefit.