Deprecated communication between tasks

Communication between tasks is facilitated by ports (in the receiving task), and channels (in the sending task). Any number of channels may feed into a single port. Ports and channels may only transmit values of unique types; that is, values that are statically guaranteed to be accessed by a single 'owner' at a time. Unique types include scalars, vectors, strings, and records, tags, tuples and unique boxes (~T) thereof. Most notably, shared boxes (@T) may not be transmitted across channels.

Example

let po = comm::Port();
let ch = comm::Chan(po);

do task::spawn {
    comm::send(ch, "Hello, World");
}

io::println(comm::recv(p));

Note

Use of this module is deprecated in favor of core::pipes. In the core::comm will likely be rewritten with pipes, at which point it will once again be the preferred module for intertask communication.

Type port_id

type port_id = int

Enum Chan

A communication endpoint that can send messages

Each channel is bound to a port when the channel is constructed, so the destination port for a channel must exist before the channel itself. Channels are weak: a channel does not keep the port it is bound to alive. If a channel attempts to send data to a dead port that data will be silently dropped. Channels may be duplicated and themselves transmitted over other channels.

Variants

Enum Port

A communication endpoint that can receive messages

Each port has a unique per-task identity and may not be replicated or transmitted. If a port value is copied, both copies refer to the same port. Ports may be associated with multiple chans.

Variants

Enum rust_port

Struct PortPtr

struct PortPtr <T: Owned>{
    po: *rust_port,
}

Implementation for Port<T>

Method chan

fn chan() -> Chan<T>

Method send

fn send(v: T)

Method recv

fn recv() -> T

Method peek

fn peek() -> bool

Implementation for Chan<T>

Method chan

fn chan() -> Chan<T>

Method send

fn send(v: T)

Method recv

fn recv() -> T

Method peek

fn peek() -> bool

Function Chan

fn Chan<T: Owned>(p: &Port<T>) -> Chan<T>

Constructs a channel. The channel is bound to the port used to construct it.

Function Port

fn Port<T: Owned>() -> Port<T>

Constructs a port

Function PortPtr

fn PortPtr<T: Owned>(po: *rust_port) -> PortPtr<T>

Function as_raw_port

fn as_raw_port<T: Owned, U>(ch: Chan<T>, f: &fn(*rust_port) -> U) -> U

Internal function for converting from a channel to a port

Failure

Fails if the port is detached or dead. Fails if the port is owned by a different task.

Function listen

fn listen<T: Owned, U>(f: &fn(Chan<T>) -> U) -> U

Open a new receiving channel for the duration of a function

Function peek

fn peek<T: Owned>(p: Port<T>) -> bool

Returns true if there are messages available

Function peek_

fn peek_(p: *rust_port) -> bool

Function peek_chan

fn peek_chan<T: Owned>(ch: Chan<T>) -> bool

Function recv

fn recv<T: Owned>(p: Port<T>) -> T

Receive from a port. If no data is available on the port then the task will block until data becomes available.

Function recv_

fn recv_<T: Owned>(p: *rust_port) -> T

Receive on a raw port pointer

Function select2

fn select2<A: Owned, B: Owned>(p_a: Port<A>, p_b: Port<B>) -> Either<A, B>

Receive on one of two ports

Function send

fn send<T: Owned>(ch: Chan<T>, data: T)

Sends data over a channel. The sent data is moved into the channel, whereupon the caller loses access to it.