use crate::executor::Executor;
pub trait FutureExt: Future {
fn block_on(self) -> Self::Output;
}
impl<F: Future> FutureExt for F {
fn block_on(self) -> Self::Output {
Executor::block_on(self)
}
}
#[cfg(test)]
mod tests {
#[rustfmt::skip]
use std::{
error,
result,
};
use super::*;
#[rustfmt::skip]
#[test]
fn block_on_result_ok() {
let x: result::Result<(), Box<dyn error::Error>> =
async {
Ok(())
}.block_on();
assert!(x.is_ok());
}
#[rustfmt::skip]
#[test]
fn block_on_result_err() {
let x: result::Result<(), &str> =
async {
Err("")
}.block_on();
assert!(x.is_err());
}
}