pub struct Recorder<T: Storage> { /* private fields */ }
Expand description
Persists records asynchronously.
You may want to use this instead of directly calling your persistence backend if you do not want
to wait for the record to be persisted, in the handler which created the record. To achieve this
Recoder spawns an actor to which all records are sent immediatly. The actor when uses the
Storage
trait to talk to your persistence backend.
Recorder takes ownership of an actor and the green thread it is running in.
Implementations§
Source§impl<T> Recorder<T>
impl<T> Recorder<T>
Sourcepub fn new(storage: T) -> Self
pub fn new(storage: T) -> Self
Constructs the recorder immediatly with a readily available storage backend. While this method is not blocking and returns control to the caller immediatly, it must still be run within the context of an async tokio runtime since it does spawn a tokio thread.
Sourcepub fn from_delayed_storage(
storage: impl Future<Output = T> + Send + 'static,
) -> Self
pub fn from_delayed_storage( storage: impl Future<Output = T> + Send + 'static, ) -> Self
Constructs the recorder storage backend which will only be available ofter the future is resolved. The recorder will be availabel immediatly though, storing all calls to save within the message buffer. Use this contructor if you want your application to start up fast without waiting for the storage backend to have syncronized with the persisted state.
While this method is not blocking and returns control to the caller immediatly, it must still be run within the context of an async tokio runtime since it does spawn a tokio thread.
Sourcepub fn save(&self, record: T::Record)
pub fn save(&self, record: T::Record)
Sends the record to the internal actor for storage. This interface is fire and forget. It will not wait for the record to be actually persisted, just place it in the channel for the actor to pick up. This is why this method is both synchronous and non blocking.