pub struct Scope<'scope, 'env: 'scope> { /* private fields */ }Expand description
A scope for spawning goroutines with bounded lifetimes.
Obtained by calling scope. Every goroutine spawned via
Scope::go is guaranteed to finish before scope returns, which
allows closures to borrow data with lifetime 'env without requiring
'static.
The type is invariant over both 'scope and 'env to prevent the
compiler from shrinking either lifetime in ways that could unsafely extend
a goroutine’s ability to access stack data.
Implementations§
Source§impl<'scope, 'env: 'scope> Scope<'scope, 'env>
impl<'scope, 'env: 'scope> Scope<'scope, 'env>
Sourcepub fn go<F, R>(&'scope self, f: F) -> ScopedJoinHandle<'scope, R>
pub fn go<F, R>(&'scope self, f: F) -> ScopedJoinHandle<'scope, R>
Spawn a goroutine in this scope.
The closure may borrow any data with lifetime 'env or longer — i.e.
anything that was alive when scope was called.
Returns a ScopedJoinHandle for optional early joining. If you do
not need the return value, simply drop the handle; the goroutine still
runs to completion before the surrounding scope returns.