Struct futures_util::future::Fuse
source · [−]pub struct Fuse<Fut> { /* private fields */ }
Expand description
Future for the fuse
method.
Implementations
sourceimpl<Fut: Future> Fuse<Fut>
impl<Fut: Future> Fuse<Fut>
sourcepub fn terminated() -> Self
pub fn terminated() -> Self
Creates a new Fuse
-wrapped future which is already terminated.
This can be useful in combination with looping and the select!
macro, which bypasses terminated futures.
Examples
use futures::channel::mpsc;
use futures::future::{Fuse, FusedFuture, FutureExt};
use futures::select;
use futures::stream::StreamExt;
use futures::pin_mut;
let (sender, mut stream) = mpsc::unbounded();
// Send a few messages into the stream
sender.unbounded_send(()).unwrap();
sender.unbounded_send(()).unwrap();
drop(sender);
// Use `Fuse::terminated()` to create an already-terminated future
// which may be instantiated later.
let foo_printer = Fuse::terminated();
pin_mut!(foo_printer);
loop {
select! {
_ = foo_printer => {},
() = stream.select_next_some() => {
if !foo_printer.is_terminated() {
println!("Foo is already being printed!");
} else {
foo_printer.set(async {
// do some other async operations
println!("Printing foo from `foo_printer` future");
}.fuse());
}
},
complete => break, // `foo_printer` is terminated and the stream is done
}
}
Trait Implementations
sourceimpl<Fut: Future> FusedFuture for Fuse<Fut>
impl<Fut: Future> FusedFuture for Fuse<Fut>
sourcefn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns true
if the underlying future should no longer be polled.
impl<'__pin, Fut> Unpin for Fuse<Fut> where
__Origin<'__pin, Fut>: Unpin,
Auto Trait Implementations
impl<Fut> RefUnwindSafe for Fuse<Fut> where
Fut: RefUnwindSafe,
impl<Fut> Send for Fuse<Fut> where
Fut: Send,
impl<Fut> Sync for Fuse<Fut> where
Fut: Sync,
impl<Fut> UnwindSafe for Fuse<Fut> where
Fut: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<F> IntoFuture for F where
F: Future,
impl<F> IntoFuture for F where
F: Future,
type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
sourcefn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more