Trait gclient::EventProcessor

source ·
pub trait EventProcessor {
    // Required methods
    fn not_waited() -> Error;
    fn proc<'life0, 'async_trait, T>(
        &'life0 mut self,
        predicate: impl 'async_trait + Fn(Event) -> Option<T> + Copy,
    ) -> Pin<Box<dyn Future<Output = Result<T>> + 'async_trait>>
       where T: 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait;
    fn proc_many<'life0, 'async_trait, T>(
        &'life0 mut self,
        predicate: impl 'async_trait + Fn(Event) -> Option<T>,
        validate: impl 'async_trait + Fn(Vec<T>) -> (Vec<T>, bool),
    ) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + 'async_trait>>
       where T: 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn message_processed<'life0, 'async_trait>(
        &'life0 mut self,
        message_id: MessageId,
    ) -> Pin<Box<dyn Future<Output = Result<DispatchStatus>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn message_processed_batch<'life0, 'async_trait>(
        &'life0 mut self,
        message_ids: impl 'async_trait + IntoIterator<Item = MessageId>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(MessageId, DispatchStatus)>>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn reply_bytes_on<'life0, 'async_trait>(
        &'life0 mut self,
        message_id: MessageId,
    ) -> Pin<Box<dyn Future<Output = Result<(MessageId, Result<Vec<u8>, String>, u128)>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn err_or_succeed<'life0, 'async_trait>(
        &'life0 mut self,
        message_id: MessageId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn err_or_succeed_batch<'life0, 'async_trait>(
        &'life0 mut self,
        message_ids: impl 'async_trait + IntoIterator<Item = MessageId>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(MessageId, Option<String>)>>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Events processing trait.

This trait minimizes a boilerplate code when processing events by providing several default implementations.

See implementation example in EventListener.

Required Methods§

source

fn not_waited() -> Error

This function is called if a received event has an unexpected type.

§Examples

Implement this function to return a not-found error:

fn not_waited() -> Error {
    Error::EventNotFoundInIterator
}
source

fn proc<'life0, 'async_trait, T>( &'life0 mut self, predicate: impl 'async_trait + Fn(Event) -> Option<T> + Copy, ) -> Pin<Box<dyn Future<Output = Result<T>> + 'async_trait>>
where T: 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Event processing function.

predicate contains specific processing logic depending on an event type.

Implementor is responsible for applying the predicate to every event to be processed and collecting their results.

This function is one of the central functions to be defined by the trait implementor.

source

fn proc_many<'life0, 'async_trait, T>( &'life0 mut self, predicate: impl 'async_trait + Fn(Event) -> Option<T>, validate: impl 'async_trait + Fn(Vec<T>) -> (Vec<T>, bool), ) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + 'async_trait>>
where T: 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Multiple events processing function.

predicate contains specific processing logic depending on an event type. validator checks whether an additional condition is met for the batch of results.

Provided Methods§

source

fn message_processed<'life0, 'async_trait>( &'life0 mut self, message_id: MessageId, ) -> Pin<Box<dyn Future<Output = Result<DispatchStatus>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check whether the message identified by message_id has been processed.

source

fn message_processed_batch<'life0, 'async_trait>( &'life0 mut self, message_ids: impl 'async_trait + IntoIterator<Item = MessageId>, ) -> Pin<Box<dyn Future<Output = Result<Vec<(MessageId, DispatchStatus)>>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check whether the batch of messages identified by corresponding message_ids has been processed.

source

fn reply_bytes_on<'life0, 'async_trait>( &'life0 mut self, message_id: MessageId, ) -> Pin<Box<dyn Future<Output = Result<(MessageId, Result<Vec<u8>, String>, u128)>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get details of a reply to the message identified by message_id.

If a reply has been received, this function returns its identifier ([MessageId]), payload’s bytes (in case of zero status code) or an error message (otherwise), and an associated value.

source

fn err_or_succeed<'life0, 'async_trait>( &'life0 mut self, message_id: MessageId, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check whether the processing of a message identified by message_id resulted in an error or has been successful.

This function returns an error message in case of an error. It is needed only due to the possibility of a message’s NotExecuted state.

source

fn err_or_succeed_batch<'life0, 'async_trait>( &'life0 mut self, message_ids: impl 'async_trait + IntoIterator<Item = MessageId>, ) -> Pin<Box<dyn Future<Output = Result<Vec<(MessageId, Option<String>)>>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check whether processing batch of messages identified by corresponding message_ids resulted in errors or has been successful.

This function returns a vector of statuses with an associated message identifier ([MessageId]). Each status can be an error message in case of an error.

Object Safety§

This trait is not object safe.

Implementors§