pub struct ScopedJoinHandle<'scope, R> { /* private fields */ }Expand description
A handle to a goroutine spawned inside a Scope.
Call join to park the current goroutine until the scoped
goroutine finishes and retrieve its result.
Dropping the handle without joining is safe — the goroutine still runs to
completion (the enclosing scope guarantees this). Any return value
or panic from an un-joined goroutine is silently discarded.
§Why join returns Result instead of the value directly
go-lib goroutines are M:N scheduled; they can migrate between OS threads.
Rust’s resume_unwind depends on C++ EH machinery that is bound to the
OS thread on which catch_unwind was called. Calling resume_unwind
after a goroutine has parked and been rescheduled on a different thread
bypasses the inner landing pad and produces undefined behaviour. Returning
std::thread::Result<R> lets the caller choose what to do — typically
.unwrap() or matching on the payload — without crossing any scheduling
boundary.
Implementations§
Source§impl<'scope, R: Send + 'static> ScopedJoinHandle<'scope, R>
impl<'scope, R: Send + 'static> ScopedJoinHandle<'scope, R>
Sourcepub fn join(self) -> Result<R>
pub fn join(self) -> Result<R>
Park the current goroutine until the scoped goroutine finishes.
Returns Ok(value) if the goroutine returned normally, or
Err(panic_payload) if it panicked.
To propagate the panic as-is call
std::panic::resume_unwind(err) from outside any goroutine
scheduling boundary — i.e., directly in the scope closure without
any intervening channel/wait operations. For the common case, .unwrap()
is usually simpler.