November 2019
Intermediate to advanced
404 pages
12h 9m
English
To process messages, our messaging system should maintain a queue of incoming message objects so that we can process them in the order they were broadcast:
private Queue<Message> _messageQueue = new Queue<Message>();public bool QueueMessage(Message msg) { if (!_listenerDict.ContainsKey(msg.type)) { return false; } _messageQueue.Enqueue(msg); return true;}
The QueueMessage() method simply checks whether the given message type is present in our dictionary before adding it to the queue. This effectively tests whether or not an object actually cares to listen to the message before we queue it to be processed later. We have introduced a new private field, _messageQueue, for this purpose.
Next, we'll add a definition ...
Read now
Unlock full access