Reputation: 253
I have a Windows Delphi application that receives events, on each of these events i'd like to run a task in a parallel way (so i can be ready for the following event). There is many way to do this through omnithread library's abstractions.
The issue is that part of my code needs to be executed immediately after the reception of the event (basically to "decode" the events params), and another part needs to be executed a few seconds after only under the condition of nothing new happend for the same context. This behaviour should respond to "only store this new value if it last longer than 3000ms, otherwise just cancel it". So what I need would be to "cancel" a running task (the one waiting 3000ms) if a new event arrives with the same context. I cannot use a pipeline abstraction because when the first stage ends, it automatically fills the second stage queue without asking me if i want to cancel it or not.
Is that possible?
Thank you.
Upvotes: 0
Views: 148
Reputation: 36654
Sounds like you need a Dictionary<Context, Event>
where the events also carry a "created" timestamp property, and a background tread which continuously checks if there are event entries in this dictionary with elapsed time > 3000ms
.
Incoming events update the timestamp and event params, until the thread detects an entry which matches the condition and then extracts the entry from the dictionary.
Upvotes: 1