pub trait Runnable {
// Required method
fn run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 RunContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}
Expand description
Runnable trait for deferred tasks Deferred tasks are often useful for logging and analytics.
use std::{rc::Rc,sync::Mutex};;
use async_trait::async_trait;
use service_logging::{log,Logger,LogQueue,Severity};
use wasm_service::{Runnable,RunContext};
struct Data { s: String }
#[async_trait]
impl Runnable for Data {
async fn run(&self, ctx: &RunContext) {
log!(ctx, Severity::Info, msg: format!("Deferred with data: {}", self.s ));
}
}
Required Methods§
Sourcefn run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 RunContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 RunContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute a deferred task. The task may append
logs to lq
using the log
macro. Logs generated
are sent to the log service after all deferred tasks have run.
Note that if there is a failure sending logs to the logging service, those log messages (and the error from the send failure) will be unreported.