6 releases

0.3.1 Oct 15, 2023
0.2.3 Jul 25, 2023
0.2.2 Apr 20, 2023
0.1.2 Apr 19, 2023

#2226 in Rust patterns

Download history 9/week @ 2024-02-23 8/week @ 2024-03-01 6/week @ 2024-03-15 59/week @ 2024-03-22 3/week @ 2024-03-29

63 downloads per month

MIT/Apache

9KB
145 lines

sod-mpsc

sod::Service implementations to interact with std::sync::mpsc queues.

Service Impls

  • MpscSender sends to a std::sync::mpsc::channel.
  • MpscSyncSender sends to a std::sync::mpsc::sync_channel and blocks if the channel is full.
  • MpscSyncTrySender tries to send to a std::sync::mpsc::sync_channel and is able to be retried via sod::RetryService when the channel is full.
  • MpscReceiver receives from a std::sync::mpsc::channel or std::sync::mpsc::sync_channel, blocking until an element is received.
  • MpscTryReceiver tries to receive from a std::sync::mpsc::channel or std::sync::mpsc::sync_channel, and is able to be retried via sod::Retryable when the channel is empty.

Example

use sod::Service;
use sod_mpsc::{MpscSender, MpscReceiver};
use std::sync::mpsc;

let (tx, rx) = mpsc::channel();
let pusher = MpscSender::new(tx);
let poller = MpscReceiver::new(rx);

pusher.process(1).unwrap();
pusher.process(2).unwrap();

assert_eq!(poller.process(()).unwrap(), 1);
assert_eq!(poller.process(()).unwrap(), 2);

Dependencies

~0.4–0.8MB
~20K SLoC