Function web_thread::web::scope_async
source · pub fn scope_async<'scope, 'env: 'scope, F1, F2, T>(
f: F1,
) -> ScopeFuture<'scope, 'env, F2, T> ⓘ
Available on
Web
only.Expand description
Async version of scope()
.
§Notes
Keep in mind that if ScopeFuture
is 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
.
§Example
let value = AtomicUsize::new(0);
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);
}).await;
assert_eq!(value.load(Ordering::Relaxed), 4);