Struct clocked_dispatch::ClockedSender [] [src]

pub struct ClockedSender<T> {
    // some fields omitted
}

The sending half of a clocked synchronous channel. This half can only be owned by one thread, but it can be cloned to send to other threads.

Sending on a clocked channel will deliver the given message to the appropriate receiver, but also notify all other receivers about the timestamp assigned to the message. The sending will never block on a receiver that is not the destination of the message.

Beware that dropping a clocked sender incurs control messages to the dispatcher, and that those control messages may result in messages being sent to receivers. If the dispatch channel is not sufficiently buffered, this means that dropping a ClockedSender before the corresponding ClockedReceiver is receiving on its end of the channel may deadlock.

When the last ClockedSender is dropped for a target, and there are no ClockedBroadcasters, the dispatcher will automatically be notified, and the recipient will see a disconnected channel error once it has read all buffered messages.

use clocked_dispatch;
use std::thread;

let m = clocked_dispatch::new(10);
let (tx_a, rx_a) = m.new("atx", "arx");

let tx_a1 = tx_a.clone("atx1");
thread::spawn(move || {
    tx_a1.send("a1");
});

let tx_a2 = tx_a.clone("atx2");
thread::spawn(move || {
    tx_a2.send("a2");
});

drop(tx_a);
assert_eq!(rx_a.count(), 2);

Methods

impl<T> ClockedSender<T>
[src]

fn send(&self, data: T)

Sends a value on this synchronous channel, and notifies all other recipients of the timestamp it is assigned by the dispatcher.

This function will block until space in the internal buffer becomes available, or a receiver is available to hand off the message to.

Note that a successful send does not guarantee that the receiver will ever see the data if there is a buffer on this channel. Items may be enqueued in the internal buffer for the receiver to receive at a later time. If the buffer size is 0, however, it can be guaranteed that the receiver has indeed received the data if this function returns success.

fn forward(&self, data: Option<T>, ts: usize)

Sends an already-sequenced value to the associated receiver. The message may be buffered by the dispatcher until it can guarantee that no other sender will later try to send messages with a lower sequence number.

It is optional to include data when forwarding. If no data is included, this message conveys to the dispatcher that this sender promises not to send later messages with a higher sequence number than the one given.

fn clone<V: Into<String>>(&self, source: V) -> ClockedSender<T>

Creates a new clocked sender for this sender's receiver.

Clocked dispatch requires that all senders have a unique name so that the "up-to-date-ness" of the senders can be tracked reliably.

impl<T: Clone> ClockedSender<T>
[src]

fn to_broadcaster(self) -> ClockedBroadcaster<T>

Converts this sender into a broadcast sender.

Doing so detaches the sender from its receiver, and means all future sends will be broadcast to all receivers. Note that the existence of a broadcaster prevents the closing of all channels.

Trait Implementations

impl<T> Drop for ClockedSender<T>
[src]

fn drop(&mut self)

A method called when the value goes out of scope. Read more