MessageManager/MessageListener request


#1

It could be very useful to have some function(s) that removes already sent Messages for a specific MessageListener from the Message Queue.


#2

That’d be an absolute nightmare to implement - the messages go via the OS, so aren’t visible until they arrive. And on OSX I’m not even sure it’s possible…


#3

One simple implementation occurs to me:

It would be possible to throw the messages away after receiving them from the OS: The MessageListener would have a hidden counter, and when it issues a message via postmessage(), the hidden counter is put inside the Message.

On reception (before handleMessage()), the MessageListener checks if the hidden counter of the received message is still equal to its own hidden counter. This is always the case except if the MessageListener has chosen to throw away the already sent messages, which is done via away function called rejectPendingMessages() that just increments the hidden counter by 1.
If the message’s counter is valid, the Message is given to handleMessage(), otherwise it is destroyed.


#4

Wow - that’d be a lot of overhead and extra complication for a feature that I can’t honestly see the point of… What’s the compelling reason for needing to do this?


#5

Is increasing and checking one single counter a “big overhead”? :slight_smile:

I needed this in one of my projects, but I just put the counter as intParameter3 into the Messages, that works as well, so it’s no big deal. You are right, it’s rather special, and I’m not sure if it would be of much use for everybody.


#6

Well, it’s not just checking a counter, it’s maintaining two counters, and adding counters to all the messages… Just all sounds like a recipe for bugs. If there was a killer reason to do it, I’d agree, but I’m sure there are always neater ways to accomplish the same thing.