thread_spawn

Function thread_spawn 

Source
pub fn thread_spawn<F, T>(name: &str, f: F) -> JoinHandle<T>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,
Expand description

Creates a new thread with the specified name and executes the provided function.

This is a convenience wrapper around the standard library’s thread creation functionality. It creates a thread with the given name and executes the provided function in that thread.

§Parameters

  • name - The name to assign to the thread.
  • f - The function to execute in the new thread.

§Returns

A JoinHandle that can be used to wait for the thread to complete and retrieve its result.

§Panics

This function will panic if thread creation fails.

§Examples

use cutoff_common::thread_spawn;
use std::sync::mpsc;

let (tx, rx) = mpsc::channel();

let handle = thread_spawn("example-thread", move || {
    tx.send("Hello from thread").unwrap();
    42 // Return value
});

assert_eq!(rx.recv().unwrap(), "Hello from thread");
assert_eq!(handle.join().unwrap(), 42);