Skip to main content

SyncHandler

Trait SyncHandler 

Source
pub trait SyncHandler: Send + Sync {
    // Required method
    fn on_sync<'life0, 'life1, 'async_trait>(
        &'life0 self,
        response: &'life1 SyncResponseModel,
    ) -> Pin<Box<dyn Future<Output = Result<(), SyncHandlerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn on_sync_complete<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for handling sync events

Implementors can register themselves with a SyncClient to receive notifications about sync operations. All handlers are called sequentially in registration order.

The sync lifecycle has two phases:

  1. on_sync — called with the raw API response for data processing
  2. on_sync_complete — called after all handlers have finished on_sync, for post-processing work

If any handler returns an error, subsequent handlers are not called and the error is propagated to the caller.

Required Methods§

Source

fn on_sync<'life0, 'life1, 'async_trait>( &'life0 self, response: &'life1 SyncResponseModel, ) -> Pin<Box<dyn Future<Output = Result<(), SyncHandlerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called after a successful sync operation

The sync response contains raw API models from the server. Handlers are responsible for converting these to domain types as needed and persisting data to local storage.

Provided Methods§

Source

fn on_sync_complete<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called after all handlers have finished processing on_sync

Override this method to perform post-processing work that should happen after all handlers have persisted their data. The default implementation is a no-op.

Implementors§