Skip to main content

ScopedJoinHandle

Struct ScopedJoinHandle 

Source
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>

Source

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.

Auto Trait Implementations§

§

impl<'scope, R> Freeze for ScopedJoinHandle<'scope, R>

§

impl<'scope, R> !RefUnwindSafe for ScopedJoinHandle<'scope, R>

§

impl<'scope, R> Send for ScopedJoinHandle<'scope, R>
where R: Send,

§

impl<'scope, R> Sync for ScopedJoinHandle<'scope, R>
where R: Send,

§

impl<'scope, R> Unpin for ScopedJoinHandle<'scope, R>

§

impl<'scope, R> UnsafeUnpin for ScopedJoinHandle<'scope, R>

§

impl<'scope, R> !UnwindSafe for ScopedJoinHandle<'scope, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.