sod-mpsc

Crates.iosod-mpsc
lib.rssod-mpsc
version0.3.4
sourcesrc
created_at2023-04-19 04:26:08.295397
updated_at2024-06-26 13:50:53.478261
descriptionService Oriented Design - Multi Producer Single Consumer
homepage
repositoryhttps://github.com/thill/sod
max_upload_size
id843180
size8,390
Eric Thill (thill)

documentation

README

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);
Commit count: 16

cargo fmt