Skip to main content

construct_thread_builder_fn_name

Function construct_thread_builder_fn_name 

Source
pub fn construct_thread_builder_fn_name() -> Ident
Expand description

Constructs thread builder fn name. This function will generate thread builder with specified name. This name will be displayed as result of thread::current().name().unwrap() or in case of thread’s panic.

§Example:

extern crate join;

use std::thread;
use join::join_spawn;

join_spawn! {
    Ok::<_, ()>("hello world") |> |value| {
        println!("{}", thread::current().name().unwrap()); // main_join_0
        value
    }
};

In runtime thread’s name will be constructed from name of parent thread and join_%branch_index%.

§Example with several branches:

extern crate join;

use std::thread;

use join::try_join_spawn;

fn current_thread_name() -> String {
    thread::current().name().unwrap().to_owned()
}

fn print_branch_thread_name(index: &Result<usize, ()>) {
    println!("Branch: {}. Thread name: {}.", index.unwrap(), current_thread_name());
}

let _ = try_join_spawn! {
    Ok(0) ?? print_branch_thread_name,
    Ok(1) ?? print_branch_thread_name,
    try_join_spawn! {
        Ok(2) ?? print_branch_thread_name,
        try_join_spawn! {
            Ok(3) ?? print_branch_thread_name,
        }
    }
}.unwrap();

// Branch: 0. Thread name: main_join_0.
// Branch: 1. Thread name: main_join_1.
// Branch: 2. Thread name: main_join_2_join_0.
// Branch: 3. Thread name: main_join_2_join_1_join_0.
// Order could be different.