pub struct ClockedSender<T> { /* private fields */ }
Expand description

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);

Implementations

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.

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.

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.

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

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.