task_receive


task_receive(@optional timeout, default)
      

Advance the mailbox cursor of the current task to the next message, remove that message from the mailbox, rewind the mailbox cursor, and return the message.

When timeout is not specified, the current task will wait until a message is available in the mailbox. When timeout is specified and default is not specified, a mailbox-receive-timeout-exception object is raised if the timeout is reached before a message is available. When timeout is specified and default is specified, the value of default is returned if the timeout is reached before a message is available.

Timeout can be an exact integer to indicate seconds or a fractional number to indicate sub-second precision.

The !< operator has the same semantics as task_receive without timeout and default specified.

Examples:


function add2()
  letseq (sender:n = task_receive())
    task_send(sender, n + 2)

let adder = task(add2)
adder !> self():10
// <task>:10
!<
// 12
      

Also see:

task_messages_next


Core Module Index | Contents