Skip to main content

execute_async_verb

Function execute_async_verb 

Source
pub fn execute_async_verb<F, T>(future: F) -> Result<T>
where F: Future<Output = Result<T>> + Send + 'static, T: Send + 'static,
Expand description

Execute an async function and convert errors to clap_noun_verb::NounVerbError

Detects if we’re already in a tokio runtime and uses Handle::current() if so, otherwise creates a new runtime. Automatically converts anyhow errors to NounVerbError for use in verb functions.

§Examples

use cli::runtime_helper::execute_async_verb;
use clap_noun_verb::Result;

#[verb("doctor", "utils")]
fn utils_doctor() -> Result<DoctorOutput> {
    execute_async_verb(async {
        run_diagnostics().await
    })
}