| Crates.io | sod-crossbeam |
| lib.rs | sod-crossbeam |
| version | 0.4.2 |
| created_at | 2023-04-20 17:09:57.76887+00 |
| updated_at | 2025-01-07 17:21:57.270679+00 |
| description | Service Oriented Design - Crossbeam |
| homepage | |
| repository | https://github.com/thill/sod |
| max_upload_size | |
| id | 844643 |
| size | 9,877 |
sod::Service implementations to interact with crossbeam queues.
ArrayQueuePusher pushes to a crossbeam::queue::ArrayQueueArrayQueueForcePusher force pushes to a crossbeam::queue::ArrayQueueArrayQueuePopper pops from a crossbeam::queue::ArrayQueueSegQueuePusher pushes to a crossbeam::queue::SegQueueSegQueuePopper pops from a crossbeam::queue::SegQueueAny of the services can be represented as an AsyncService using self.into_async().
use crossbeam::queue::ArrayQueue;
use sod::{PollService, Service};
use sod_crossbeam::ArrayQueuePopper;
use std::{sync::Arc, time::Duration};
let q = Arc::new(ArrayQueue::<i32>::new(128));
let async_popper = ArrayQueuePopper::new(Arc::clone(&q)).into_mut();
sod::PollService may encapsulate a ArrayQueuePopper or SegQueuePopper to provide a backoff mechanism to avoid busy-spinning the CPU in a poll loop.
use crossbeam::queue::ArrayQueue;
use sod::{idle::backoff, PollService, Service};
use sod_crossbeam::ArrayQueuePopper;
use std::{sync::Arc, time::Duration};
let q = Arc::new(ArrayQueue::<i32>::new(128));
let popper = PollService::new(ArrayQueuePopper::new(Arc::clone(&q)), backoff);
loop {
println!("received: {}", popper.process(()).unwrap());
}
sod::RetryService may encapsulate a ArrayQueuePusher to block and continuously retry pushing an element to an ArrayQueue until it succeeds.
use crossbeam::queue::ArrayQueue;
use sod::{RetryService, Service, idle::yielding};
use sod_crossbeam::ArrayQueuePusher;
use std::sync::Arc;
let q = Arc::new(ArrayQueue::new(128));
let pusher = RetryService::new(ArrayQueuePusher::new(Arc::clone(&q)), yielding);
pusher.process(123).unwrap();
pusher.process(456).unwrap();