FixTask Documentation
Back to summary
import "task/channel";
Channel class
Channel allows to send messages between different tasks. The channel can be either
synchronous (the message is directly exchanged between the tasks at synchronization
point) or asynchronous by using a queue.
When sending channels as a part of the message using the asynchronous variant of the
channel the values are only weakly referenced to prevent memory leaks. An outside reference
must be present (this is usually the case).
Functions
static function create(): Channel
static function create(size: Integer): Channel
-
Creates a new channel. When the size is non-zero an asynchronous channel
is created with the given queue size.
function send(msg)
function send(msg, timeout: Integer): Boolean
-
Sends a message to the channel with an optional timeout (in milliseconds,
negative value disables the timeout). Returns true if the message was
delivered (when using timeout).
function receive(): Dynamic
function receive(timeout: Integer): Dynamic
function receive(timeout: Integer, timeout_value): Dynamic
-
Receives a message from the channel with an optional timeout (in milliseconds,
negative value disables the timeout). If the message wasn't received within
the provided time limit a special marker value is returned which you can check
using the
is_timeout
function.
function get_sender(): Channel
function get_receiver(): Channel
-
Returns either the sender or receiver part of the channel to prevent inappropriate
usage.
function get_shared_count(): Integer
-
Returns the reference count of the channel. Can be used to track liveness of the
channel in other tasks in a similar fashion as shared arrays
can be used.
function set_size(size: Integer)
function get_size(): Integer
-
Allows to adjust or get the queue size for asynchronous channels.
function call(params: Dynamic[]): Dynamic
-
Uses the channel to do a synchronous function call (from the caller's point of view
at least). It just appends an internal return channel to the provided parameters and
is sent to the channel. It then waits for a message in the return channel to return.
The returned value must be an array of one or two return values, or it can be
null
to not return anything.
Special values
static function is_timeout(value): Boolean
-
Returns true if the returned value is a special marker value denoting that a time
limit has been reached.
static function is_error(value): Boolean
-
Returns true if the returned value is a special marker value denoting that an
error has occurred.