Struct web_thread::web::ScopeFuture
source · pub struct ScopeFuture<'scope, 'env, F, T>(/* private fields */);
Available on
Web
only.Expand description
Waits for the associated scope to finish. See scope_async()
.
§Notes
Keep in mind that if dropped it will block, or spinloop if blocking is not
supported on this thread (see has_block_support()
), until all threads
are joined but does not continue polling the passed Future
.
Implementations§
source§impl<'scope, 'env, F, T> ScopeFuture<'scope, 'env, F, T>
impl<'scope, 'env, F, T> ScopeFuture<'scope, 'env, F, T>
sourcepub const fn into_wait(self) -> ScopeIntoJoinFuture<'scope, 'env, F, T> ⓘ
pub const fn into_wait(self) -> ScopeIntoJoinFuture<'scope, 'env, F, T> ⓘ
Converts this ScopeFuture
to a ScopeJoinFuture
by waiting until
the given Future
to scope_async()
is finished.
This is useful to:
- Use
ScopeJoinFuture::join_all()
. - Be able to drop
ScopeJoinFuture
while guaranteeing that the givenFuture
toscope_async()
is finished. - Get rid of
F
which often preventsScopeFuture
from implementingUnpin
.
§Example
let value = AtomicUsize::new(0);
let future = web_thread::web::scope_async(|scope| async {
(0..3).for_each(|_| {
scope.spawn(|| value.fetch_add(1, Ordering::Relaxed));
});
value.fetch_add(1, Ordering::Relaxed);
}).into_wait().await;
// This will block until all threads are done.
drop(future);
assert_eq!(value.load(Ordering::Relaxed), 4);
Trait Implementations§
source§impl<F, T> Debug for ScopeFuture<'_, '_, F, T>
impl<F, T> Debug for ScopeFuture<'_, '_, F, T>
source§impl<F, T> Future for ScopeFuture<'_, '_, F, T>where
F: Future<Output = T>,
impl<F, T> Future for ScopeFuture<'_, '_, F, T>where
F: Future<Output = T>,
impl<'pin, 'scope, 'env, F, T> Unpin for ScopeFuture<'scope, 'env, F, T>where
__ScopeFuture<'pin, 'scope, 'env, F, T>: Unpin,
Auto Trait Implementations§
impl<'scope, 'env, F, T> Freeze for ScopeFuture<'scope, 'env, F, T>
impl<'scope, 'env, F, T> RefUnwindSafe for ScopeFuture<'scope, 'env, F, T>where
F: RefUnwindSafe,
T: RefUnwindSafe,
impl<'scope, 'env, F, T> Send for ScopeFuture<'scope, 'env, F, T>
impl<'scope, 'env, F, T> Sync for ScopeFuture<'scope, 'env, F, T>
impl<'scope, 'env, F, T> !UnwindSafe for ScopeFuture<'scope, 'env, F, T>
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
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