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

EMPTY

Boolean

true if there are no messages in the queue

LENGTH

Scalar

number of messages in the queue

POP()

Message

returns the oldest element in the queue and removes it

PEEK()

Message

returns the oldest element in the queue without removing it

CLEAR()

None

remove all messages

PUSH(message)

None

explicitly append a message

MessageQueue:EMPTY
Type

Boolean

True if there are no messages in this queue.

MessageQueue:LENGTH
Type

Scalar

Number of messages in this queue.

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

Message

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
  • messageMessage 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 and Message:SENDER) will not be changed.