sod::Service
implementations to interact with crossbeam
queues.
ArrayQueuePusher
pushes to a crossbeam::queue::ArrayQueue
ArrayQueueForcePusher
force pushes to a crossbeam::queue::ArrayQueue
ArrayQueuePopper
pops from a crossbeam::queue::ArrayQueue
SegQueuePusher
pushes to a crossbeam::queue::SegQueue
SegQueuePopper
pops from a crossbeam::queue::SegQueue
Any of the services can be represented as an AsyncService
using self.into_async()
.
``` use crossbeam::queue::ArrayQueue; use sod::{PollService, IntoMutService, Service}; use sod_crossbeam::ArrayQueuePopper; use std::{sync::Arc, time::Duration};
let q = Arc::new(ArrayQueue::
sod::PollService
may encapsulate a ArrayQueuePopper
or SegQueuePopper
to provide a backoff mechanism to avoid busy-spinning the CPU in a poll loop.
```rust 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::
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.
```rust 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(); ```