pub struct ConcurrentService<S>{ /* private fields */ }Expand description
A service that handles messages concurrently.
When the service reaches its maximum concurrency, it either drops messages or keeps them in the input queue.
use relay_system::{Interface, SimpleService, LoadShed, ConcurrentService};
#[derive(Clone)]
struct MyService;
struct MyMessage;
impl Interface for MyMessage {}
impl SimpleService for MyService {
type Interface = MyMessage;
async fn handle_message(&self, message: MyMessage) {
// do your thing
}
}
// `Loadshed` implementation is required but can be empty.
impl LoadShed<MyMessage> for MyService {
fn handle_loadshed(&self, _: MyMessage) {
eprintln!("Dropped a message!");
}
}
let concurrent_service = ConcurrentService::new(MyService).with_concurrency_limit(5);Implementations§
Source§impl<S> ConcurrentService<S>
impl<S> ConcurrentService<S>
Sourcepub fn new(inner: S) -> Self
pub fn new(inner: S) -> Self
Creates a new concurrent service from a SimpleService.
The default strategy for congestion control is to keep messages in the input queue.
Sourcepub fn with_concurrency_limit(self, limit: usize) -> Self
pub fn with_concurrency_limit(self, limit: usize) -> Self
Sets the maximum number of messages that can be handled concurrently.
Sourcepub fn with_backlog_limit(self, limit: usize) -> Self
pub fn with_backlog_limit(self, limit: usize) -> Self
Limits the amount of messages that wait in the queue by loadshedding.
Setting this limit will cause message loss.
Note that cleanup of the queue may be deferred until the next pending future completes.
Trait Implementations§
Source§impl<S> Service for ConcurrentService<S>
impl<S> Service for ConcurrentService<S>
Source§type Interface = <S as SimpleService>::Interface
type Interface = <S as SimpleService>::Interface
The interface of messages this service implements. Read more
Source§async fn run(self, rx: Receiver<Self::Interface>)
async fn run(self, rx: Receiver<Self::Interface>)
Defines the main task of this service. Read more
Auto Trait Implementations§
impl<S> !Freeze for ConcurrentService<S>
impl<S> !RefUnwindSafe for ConcurrentService<S>
impl<S> Send for ConcurrentService<S>
impl<S> !Sync for ConcurrentService<S>
impl<S> Unpin for ConcurrentService<S>where
S: Unpin,
impl<S> !UnwindSafe for ConcurrentService<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more