ConcurrentService

Struct ConcurrentService 

Source
pub struct ConcurrentService<S>
where S: SimpleService + Clone + Send + Sync,
{ /* 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>
where S: SimpleService + Clone + Send + Sync,

Source

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.

Source

pub fn with_concurrency_limit(self, limit: usize) -> Self

Sets the maximum number of messages that can be handled concurrently.

Source

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>
where S: SimpleService + LoadShed<S::Interface> + Clone + Send + Sync + 'static,

Source§

type Interface = <S as SimpleService>::Interface

The interface of messages this service implements. Read more
Source§

async fn run(self, rx: Receiver<Self::Interface>)

Defines the main task of this service. Read more
Source§

fn start_detached(self) -> Addr<Self::Interface>

Starts the service in the current runtime and returns an address for it. Read more
Source§

fn name() -> &'static str

Returns a unique name for this service implementation. 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T