Function wora::exec_async_runner

source ·
pub async fn exec_async_runner<T: Debug + Send + Sync + 'static>(
    exec: impl AsyncExecutor<T> + Sync + Send + Executor,
    app: impl App<T> + Sync + Send + 'static,
    fs: WFS,
    metrics: impl MetricProcessor + Sync + Send
) -> Result<(), MainEarlyReturn>
Expand description

Run apps via an async based executor

Examples found in repository?
examples/basic.rs (line 103)
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
async fn main() -> Result<(), MainEarlyReturn> {
    tracing_subscriber::fmt::init();

    let app_name = "wora_basic";

    let args = BasicAppOpts::parse();

    let app = BasicApp {
        args: args,
        counter: 1,
    };

    let fs = LocalFS::new().unwrap();
    let metrics = MetricsProducerStdout::new().await;
    match UnixLikeUser::new(app_name).await {
        Ok(exec) => exec_async_runner(exec, app, fs, metrics).await?,
        Err(exec_err) => {
            error!("exec error:{}", exec_err);
            return Err(MainEarlyReturn::IO(exec_err));
        }
    }

    Ok(())
}
More examples
Hide additional examples
examples/async_daemon.rs (line 220)
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
async fn main() -> Result<(), MainEarlyReturn> {
    let filter = filter::LevelFilter::TRACE;
    let (filter, reload_handle) = reload::Layer::new(filter);

    let format = tracing_subscriber::fmt::format()
        .with_file(true)
        .with_line_number(true)
        .with_level(true) // don't include levels in formatted output
        .with_target(true) // don't include targets
        .with_thread_ids(true) // include the thread ID of the current thread
        .with_thread_names(true) // include the name of the current thread
        ; // use the `Compact` formatting style.

    let x = tracing_subscriber::fmt::layer()
        .event_format(format)
        //.with_max_level(Level::TRACE)
        .with_span_events(FmtSpan::CLOSE | FmtSpan::ENTER);

    tracing_subscriber::registry().with(filter).with(x).init();

    let args = DaemonArgs::parse();

    let app_state = DaemonState {};

    let app = DaemonApp {
        args: args.clone(),
        state: Arc::new(RwLock::new(app_state)),
        log_reload_handle: reload_handle,
        config: DaemonConfig::default(),
    };

    let metrics = MetricsProducerStdout::new().await;
    let fs = LocalFS::new().unwrap();
    match &args.run_mode {
        RunMode::Sys => {
            let exec = UnixLikeSystem::new(app.name()).await;
            exec_async_runner(exec, app, fs, metrics).await?
        }
        RunMode::User => match UnixLikeUser::new(app.name()).await {
            Ok(exec) => exec_async_runner(exec, app, fs, metrics).await?,
            Err(exec_err) => {
                error!("exec error:{}", exec_err);
                return Err(MainEarlyReturn::IO(exec_err));
            }
        },
    }

    Ok(())
}