The Sender

Now that we've covered the Receiver, all that remains is the Sender. It's defined in src/sender.rs. The most important function in the Sender is send. The Sender follows the same disk/memory mode idea that Receiver uses but is more complicated in its operation. Let's dig in:

        let mut back_guard = self.mem_buffer.lock_back();
        if (*back_guard).inner.total_disk_writes == 0 {
            // in-memory mode
            let placed_event = private::Placement::Memory(event);
            match self.mem_buffer.push_back(placed_event, &mut  back_guard) { Ok(must_wake_receiver) => { if must_wake_receiver { let front_guard = self.mem_buffer.lock_front(); self.mem_buffer.notify_not_empty(&front_guard); drop(front_guard); } } Err(deque::Error::Full(placed_event)) => { self.write_to_disk(placed_event.extract().unwrap(), ...

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.