Crates.io | sod-bus |
lib.rs | sod-bus |
version | 0.3.4 |
source | src |
created_at | 2023-04-20 17:33:40.68062 |
updated_at | 2024-06-26 13:50:34.438865 |
description | Service Oriented Design - Single Producer Multi Consumer |
homepage | |
repository | https://github.com/thill/sod |
max_upload_size | |
id | 844651 |
size | 9,411 |
sod::MutService
implementations to interact with bus::Bus
.
BusBroadcaster
broadcasts to a bus::Bus
and blocks until the operation is successful.BusTryBroadcaster
tries to broadcast to a bus::Bus
and is able to be retried via sod::RetryService
when the bus buffer is full.BusReceiver
receives from a bus::BusReader
, blocking until an element is received.BusTryReceiver
tries to receive from a bus::BusReader
and is able to be retried via sod::RetryService
when the bus is empty.use sod::MutService;
use sod_bus::{BusBroadcaster, BusReceiver};
let mut broadcaster = BusBroadcaster::with_len(1024);
let mut receiver1 = broadcaster.create_receiver();
let mut receiver2 = broadcaster.create_receiver();
broadcaster.process(1).unwrap();
broadcaster.process(2).unwrap();
broadcaster.process(3).unwrap();
assert_eq!(receiver1.process(()).unwrap(), 1);
assert_eq!(receiver1.process(()).unwrap(), 2);
assert_eq!(receiver1.process(()).unwrap(), 3);
assert_eq!(receiver2.process(()).unwrap(), 1);
assert_eq!(receiver2.process(()).unwrap(), 2);
assert_eq!(receiver2.process(()).unwrap(), 3);