Struct microasync_util::QueuedRuntime
source · pub struct QueuedRuntime { /* private fields */ }
Expand description
A very small async runtime, with support for adding more tasks as it runs. This uses a VecDeque internally.
Implementations§
source§impl QueuedRuntime
impl QueuedRuntime
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty QueuedRuntime. Awaiting this does nothing unless futures are pushed to it.
Examples found in repository?
More examples
sourcepub fn new_with_boxed(future: BoxFuture<'static, ()>) -> Self
pub fn new_with_boxed(future: BoxFuture<'static, ()>) -> Self
Creates a new QueuedRuntime. Unlike new(), this adds a single future immediately, so awaiting this will have an effect.
sourcepub fn new_with(future: impl Future<Output = ()> + 'static) -> Self
pub fn new_with(future: impl Future<Output = ()> + 'static) -> Self
Creates a new QueuedRuntime. Unlike new(), this adds a single future immediately, so awaiting this will have an effect.
sourcepub fn push_boxed(&mut self, future: BoxFuture<'static, ()>) -> &mut Self
pub fn push_boxed(&mut self, future: BoxFuture<'static, ()>) -> &mut Self
Adds a new future to the queue to be completed.
sourcepub fn push(&mut self, future: impl Future<Output = ()> + 'static) -> &mut Self
pub fn push(&mut self, future: impl Future<Output = ()> + 'static) -> &mut Self
Adds a new future to the queue to be completed.
Examples found in repository?
examples/tcp.rs (line 15)
13 14 15 16 17 18 19 20 21 22 23 24 25 26
fn main() {
let mut runtime = QueuedRuntime::new();
runtime.push(go(("0.0.0.0", 5000)));
sync(runtime);
}
async fn go(addr: (&str, u16)) {
let mut listener = TcpListener::bind(addr).unwrap();
loop {
get_current_runtime()
.await
.push(handle(accept(&mut listener).await.unwrap()));
}
}
More examples
examples/recursion.rs (line 6)
4 5 6 7 8 9 10 11 12 13 14 15 16
fn main() {
let mut runtime = QueuedRuntime::new();
runtime.push(print_something_after_ms(0));
sync(runtime);
}
async fn print_something_after_ms(ms: u64) {
wait_ms(ms).await;
println!("something after {ms}ms! :D");
get_current_runtime()
.await
.push(print_something_after_ms(ms + 1));
}
Trait Implementations§
source§impl Default for QueuedRuntime
impl Default for QueuedRuntime
source§impl Future for QueuedRuntime
impl Future for QueuedRuntime
Auto Trait Implementations§
impl !RefUnwindSafe for QueuedRuntime
impl !Send for QueuedRuntime
impl !Sync for QueuedRuntime
impl Unpin for QueuedRuntime
impl !UnwindSafe for QueuedRuntime
Blanket Implementations§
source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more