pub struct Shared<F: Future> { /* private fields */ }Expand description
A cloneable future that drives F through whichever clone is polled and resolves every clone
to a clone of its output.
Several tasks can wait on one future without a task of its own, and each completes even if the clone that created the future is never polled again. Clones complete together, and a clone polled after completion resolves immediately. Dropping the last clone drops the inner future, or its output, after which no WeakShared handle can recover it.
Polling requires F to be Unpin (box it first otherwise) and its output to be Clone.
The shared state is itself the inner future’s waker, and a waker must be 'static, Send,
and Sync, so F must also be Send and 'static, and its output Send and Sync.
§Liveness
Exactly one clone polls the inner future at a time. A clone polled meanwhile registers its waker and returns Poll::Pending without waiting for that poll. A clone’s waker stays registered until the clone completes or is dropped, and waking the inner future wakes every registered clone. If the inner future is woken while a clone polls it, or another clone finds it busy meanwhile, the polling clone wakes every other clone again once it stops polling, so a clone that went back to sleep after finding the inner future busy observes what that poll did and polls the inner future if it was woken. Progress therefore never depends on any particular clone being polled again. A clone may stop polling, because it is dropped or finished through another path, without stranding the others. A clone polled when the inner future was not woken since its last poll only registers, so the inner future is polled about once per wake however many clones are woken.
§Panics
A panic while polling the inner future propagates to the polling clone and poisons the future. Every waiting clone is woken, and polling any clone afterwards panics.
§Wakers
Registered wakers are cloned while the shared state is locked, and that lock is not reentrant, so cloning a registered waker must not wake this future’s inner future, or poll or drop one of its clones. Wakes, and drops of displaced wakers, happen after unlocking.
Implementations§
Sourcepub fn downgrade(&self) -> WeakShared<F>
pub fn downgrade(&self) -> WeakShared<F>
Create a WeakShared handle to this future.
Trait Implementations§
Auto Trait Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F> ⓘ
fn map<U, F>(self, f: F) -> Map<Self, F> ⓘ
Source§fn map_into<U>(self) -> MapInto<Self, U> ⓘ
fn map_into<U>(self) -> MapInto<Self, U> ⓘ
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> ⓘ
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> ⓘ
f. Read moreSource§fn left_future<B>(self) -> Either<Self, B> ⓘ
fn left_future<B>(self) -> Either<Self, B> ⓘ
Source§fn right_future<A>(self) -> Either<A, Self> ⓘ
fn right_future<A>(self) -> Either<A, Self> ⓘ
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self> ⓘ
fn flatten(self) -> Flatten<Self> ⓘ
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self> ⓘwhere
Self: Sized,
fn fuse(self) -> Fuse<Self> ⓘwhere
Self: Sized,
poll will never again be called once it has
completed. This method can be used to turn any Future into a
FusedFuture. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘ
fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘ
Source§fn catch_unwind(self) -> CatchUnwind<Self> ⓘwhere
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self> ⓘwhere
Self: Sized + UnwindSafe,
Source§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
() on completion and sends
its output to another future on a separate task. Read moreSource§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self> ⓘwhere
Self: Sized,
fn unit_error(self) -> UnitError<Self> ⓘwhere
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = ()>.Source§fn never_error(self) -> NeverError<Self> ⓘwhere
Self: Sized,
fn never_error(self) -> NeverError<Self> ⓘwhere
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = Never>.