Don't require Send + 'static for block_on
This commit is contained in:
parent
c7e8c6fa9c
commit
2f02b8f901
|
@ -18,5 +18,5 @@ fn main() -> Result<(), jive::task::JoinError> {
|
|||
}
|
||||
|
||||
Ok(())
|
||||
})?
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::time::Duration;
|
|||
fn main() -> Result<(), jive::task::JoinError> {
|
||||
jive::block_on(async move {
|
||||
jive::spawn(async move {
|
||||
let listener = match Async::bind(([127, 0, 0, 1], 3456)).await {
|
||||
let mut listener = match Async::bind(([127, 0, 0, 1], 3456)).await {
|
||||
Ok(listener) => listener,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ fn main() -> Result<(), jive::task::JoinError> {
|
|||
println!("Listening on port 3456");
|
||||
|
||||
loop {
|
||||
let (stream, _addr) = match listener.accept().await {
|
||||
let (mut stream, _addr) = match listener.accept().await {
|
||||
Ok(tup) => tup,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
@ -79,5 +79,6 @@ fn main() -> Result<(), jive::task::JoinError> {
|
|||
|
||||
jive::time::sleep(Duration::from_secs(60 * 2)).await;
|
||||
println!("Stopping");
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ fn length_head(content_length: usize) -> Vec<u8> {
|
|||
.into_bytes()
|
||||
}
|
||||
|
||||
fn main() -> Result<(), jive::task::JoinError> {
|
||||
fn main() {
|
||||
jive::block_on(async move {
|
||||
let listener = match Async::bind(([127, 0, 0, 1], 3456)).await {
|
||||
let mut listener = match Async::bind(([127, 0, 0, 1], 3456)).await {
|
||||
Ok(listener) => listener,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
@ -22,7 +22,7 @@ fn main() -> Result<(), jive::task::JoinError> {
|
|||
println!("Listening on port 3456");
|
||||
|
||||
loop {
|
||||
let (stream, _addr) = match listener.accept().await {
|
||||
let (mut stream, _addr) = match listener.accept().await {
|
||||
Ok(tup) => tup,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
|
|
@ -18,5 +18,5 @@ fn main() -> Result<(), jive::task::JoinError> {
|
|||
}
|
||||
|
||||
Ok(())
|
||||
})?
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ pub use task::{spawn, spawn_blocking};
|
|||
|
||||
pub fn block_on<T: Send + 'static>(
|
||||
future: impl std::future::Future<Output = T> + Send + 'static,
|
||||
) -> Result<T, jitterbug::JoinError> {
|
||||
) -> T {
|
||||
runtime::Runtime::new().block_on(future)
|
||||
}
|
||||
|
|
|
@ -87,13 +87,10 @@ impl RuntimeHandle {
|
|||
self.blocking.spawn(async move { (callback)() })
|
||||
}
|
||||
|
||||
pub fn block_on<T: Send + 'static>(
|
||||
&self,
|
||||
future: impl Future<Output = T> + Send + 'static,
|
||||
) -> Result<T, jitterbug::JoinError> {
|
||||
pub fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
|
||||
let token = RuntimeState::install(&self.executor, &self.blocking);
|
||||
|
||||
let res = foxtrot::block_on(self.executor.run_with(future)).unwrap();
|
||||
let res = foxtrot::block_on(future).unwrap();
|
||||
|
||||
drop(token);
|
||||
|
||||
|
@ -185,7 +182,7 @@ impl Runtime {
|
|||
pub fn block_on<T: Send + 'static>(
|
||||
&self,
|
||||
future: impl Future<Output = T> + Send + 'static,
|
||||
) -> Result<T, jitterbug::JoinError> {
|
||||
) -> T {
|
||||
self.handle().block_on(future)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue