MessageQueue¶
Just like ordinary queues message queues work according to First-In first-out principle.
You can read more about queues on Wikipedia.
Whenever you send a message to a CPU or a vessel it gets added to the end of that CPU’s or vessel’s message queue. The recipient can then read those messages from the queue.
Accessing message queues¶
You can access the current processor’s message queue using CORE:MESSAGES:
SET QUEUE TO CORE:MESSAGES.
PRINT "Number of messages on the queue: " + QUEUE:LENGTH.
The current vessel’s message queue can be accessed using Vessel:MESSAGES:
SET QUEUE TO SHIP:MESSAGES.
Structure¶
-
structure
MessageQueue¶ Suffix Type Description EMPTYBooleantrue if there are messages in the queue LENGTHScalarnumber of messages in the queue POP()Messagereturns the oldest element in the queue and removes it PEEK()Messagereturns the oldest element in the queue without removing it CLEAR()None remove all messages PUSH(message)None explicitly append a message
-
MessageQueue:
POP()¶ Returns the first (oldest) message in the queue and removes it. Messages in the queue are always ordered by their arrival date.
-
MessageQueue:
PEEK()¶ Returns: MessageReturns the oldest message in the queue without removing it from the queue.
-
MessageQueue:
CLEAR()¶ Removes all messages from the queue.
-
MessageQueue:
PUSH(message)¶ Parameters: - message –
Messagemessage to be added
You can use this message to explicitly add a message to this queue. This will insert this exact message to the queue, all attributes that are normally added automatically by kOS (
Message:SENTAT,Message:RECEIVEDATandMessage:SENDER) will not be changed.- message –