The Receiver

Now that we've covered the deque, let's jump on to the Receiver, defined in src/receiver.rs. As mentioned previously, the receiver is responsible for either pulling a value out of memory or from disk in the style of an iterator. The Receiver declares the usual machinery for transforming itself into an iterator, and we won't cover that in this book, mostly just because it's a touch on the tedious side. That said, there are two important functions to cover in the Receiver, and neither of them are in the public interface. The first is Receiver::next_value, called by the iterator version of the receiver. This function is defined as follows:

fn next_value(&mut self) -> Option<T> { loop { if self.disk_writes_to_read == 0 { match self.mem_buffer.pop_front() ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.