Skip to navigation
How to call a sync function from an async function and from there call again an async function in rust
29.01.26
# how to call a sync function from an async function and from there call again an async function in rust ## call a sync from async ``` use tokio::task; let target_value = match task::spawn_blocking(move || translatex(&pool, &p.s, &p.t, &p.html, wait)).await { Ok(v) => v, // the function returned successfully Err(e) => e.to_string(), }; ``` ## call an async from sync ``` let rt = tokio::runtime::Runtime::new().unwrap(); let x = rt.block_on(xtrans(&pool, source_lang, target_lang, &old_text, wait)); ```
https://docs.rs/tokio/latest/tokio/
Reply
Anonymous
Information Epoch 1770132929
Make every program a filter.
Home
Notebook
Contact us