pub struct BlockingFuture<R: Sync + Send + 'static>(/* private fields */);
Expand description
For the use in blocking context, spawn a future into given tokio runtime and wait for result.
§example:
use tokio::time::*;
use sync_utils::blocking_async::BlockingFuture;
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.worker_threads(1)
.build()
.unwrap();
let res = BlockingFuture::new().block_on(&rt, async move {
println!("exec future");
sleep(Duration::from_secs(1)).await;
return "hello world".to_string();
});
Implementations§
Auto Trait Implementations§
impl<R> Freeze for BlockingFuture<R>
impl<R> !RefUnwindSafe for BlockingFuture<R>
impl<R> Send for BlockingFuture<R>where
R: Clone,
impl<R> Sync for BlockingFuture<R>where
R: Clone,
impl<R> Unpin for BlockingFuture<R>
impl<R> !UnwindSafe for BlockingFuture<R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more