pub async fn async_scope<R, F: Future<Output = R> + UnwindSafe, DTORARGS, DTOR: Future<Output = ()>, DTORFN: FnOnce(DTORARGS) -> DTOR>(
dtor: DTORFN,
args: DTORARGS,
fut: F,
) -> RExpand description
Executes future, making sure to perform cleanup regardless of whether fut is successful or
panics.
§Arguments:
dtor- Generic callback that acceptsargsas its only incoming parameter;args- Generic arguments that are passed as it is to thedtor;fut- Future to execute before callingdtor. Regardless of success,dtoris always executed.
Returns Output of fut or panics on error in executing fut.
Regardless of fut execution status, dtor is always called.
§Example
use scope_guard::async_scope;
async fn dtor(_args: ()) {
println!("dtor!");
}
async fn example() {
let fut = async {
panic!("FAIL")
};
async_scope(dtor, (), fut).await;
}