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
true if there are no messages in the queue
number of messages in the queue
returns the oldest element in the queue and removes it
returns the oldest element in the queue without removing it
None
remove all messages
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
Returns 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 –
Message
message 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:RECEIVEDAT
andMessage:SENDER
) will not be changed.