pub fn with_async_context<C, T, F>(ctx: C, future: F) -> AsyncContext<C, T, F> ⓘ
Expand description
Creates a new async context and executes the provided future within it
§Arguments
ctx
- The context data to make available during future executionfuture
- The future to execute within the context
§Panics
Panics if attempting to create a nested context when one already exists
§Examples
use with_async_context::with_async_context;
struct MyContext;
impl MyContext {
fn new() -> Self {
MyContext
}
}
impl ToString for MyContext {
fn to_string(&self) -> String {
"MyContext".into()
}
}
async fn async_function() {}
let result = with_async_context(
MyContext::new(),
async_function()
).await;