Repository: tokio-rs/tokio
File: tokio/src/runtime/handle.rs (Rust)

Code before:
    /// let handle = rt.handle();
    ///
    /// // Spawn a blocking function onto the runtime using the handle
    /// handle.spawn_blocking(|| {
    ///     println!("now running on a worker thread");
    /// });
    /// # }
    #[track_caller]
    pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
    where
        F: FnOnce() -> R + Send + 'static,
        R: Send + 'static,
    {
        if cfg!(debug_assertions) && std::mem::size_of::<F>() > 2048 {
            self.spawn_blocking_inner(Box::new(func), false, None)
        } else {
            self.spawn_blocking_inner(func, false, None)
        }
    }

    cfg_fs! {
        #[track_caller]
        pub(crate) fn spawn_mandatory_blocking<F, R>(&self, func: F) -> JoinHandle<R>
        where
            F: FnOnce() -> R + Send + 'static,
        R: Send + 'static,
        {
            if cfg!(debug_assertions) && std::mem::size_of::<F>() > 2048 {
                self.spawn_blocking_inner(Box::new(func), true, None)
            } else {
                self.spawn_blocking_inner(func, true, None)
            }
        }
    }

    #[track_caller]
    pub(crate) fn spawn_blocking_inner<F, R>(
        &self,
        func: F,
        is_mandatory: bool,
        name: Option<&str>,
    ) -> JoinHandle<R>
    where
        F: FnOnce() -> R + Send + 'static,
        R: Send + 'static,
    {
        let fut = BlockingTask::new(func);

        #[cfg(all(tokio_unstable, feature = "tracing"))]
        let fut = {
            use tracing::Instrument;

Review comment (suggestion):
```suggestion
            F: FnOnce() -> R + Send + 'static,
            R: Send + 'static,
```

Code after:
    pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
    where
        F: FnOnce() -> R + Send + 'static,
        R: Send + 'static,
    {
        let (join_handle, _was_spawned) =
            if cfg!(debug_assertions) && std::mem::size_of::<F>() > 2048 {
                self.spawn_blocking_inner(Box::new(func), blocking::Mandatory::NonMandatory, None)
            } else {
                self.spawn_blocking_inner(func, blocking::Mandatory::NonMandatory, None)
            };

        join_handle
    }

    cfg_fs! {
        #[track_caller]
        #[cfg_attr(any(
            all(loom, not(test)), // the function is covered by loom tests
            test
        ), allow(dead_code))]
        pub(crate) fn spawn_mandatory_blocking<F, R>(&self, func: F) -> Option<JoinHandle<R>>
        where
            F: FnOnce() -> R + Send + 'static,
            R: Send + 'static,
        {
            let (join_handle, was_spawned) = if cfg!(debug_assertions) && std::mem::size_of::<F>() > 2048 {
                self.spawn_blocking_inner(
                    Box::new(func),
                    blocking::Mandatory::Mandatory,
                    None
                )
            } else {
                self.spawn_blocking_inner(
                    func,
                    blocking::Mandatory::Mandatory,
                    None
                )
            };

            if was_spawned {
                Some(join_handle)
            } else {
                None
            }
        }
    }

    #[track_caller]
    pub(crate) fn spawn_blocking_inner<F, R>(
        &self,