send Message
suspend fun <M : AgentMessage> KSLProcessBuilder.sendMessage(message: M, mailbox: AgentModel.AgentMailbox<M>)(source)
Send message to mailbox from inside an agent's process { } body. Non-blocking: the mailbox is unbounded and deliver always succeeds. Declared suspend only to be callable from restricted-suspension lambdas; no actual suspension occurs.
If a peer is currently suspended in receiveMessage on mailbox with a matching predicate, the message is handed directly to that waiter and the peer is scheduled to resume — bypassing the pending queue entirely. Otherwise the message is queued and any registered arrival listeners (statechart hooks) are fired.
val behavior = process {
sendMessage(AgentMessage.Inform(this@MyAgent, "hello"), peer.mailbox)
}Content copied to clipboard