1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
*
* Copyright (c) 2025 - 2026.
* Haixing Hu, Qubit Co. Ltd.
*
* All rights reserved.
*
******************************************************************************/
use thread;
use Callable;
use crate::;
use Executor;
/// Executes each task on a dedicated OS thread.
///
/// This executor does not manage lifecycle or maintain a queue. Each accepted
/// task receives a [`TaskHandle`] that can be used to wait for the result.
///
/// # Semantics
///
/// * **One task, one thread** — each [`Executor::call`] or [`Executor::execute`]
/// spawns a new [`std::thread::spawn`] worker. There is no pool and no
/// submission queue.
/// * **Blocking or async wait** — [`TaskHandle::get`] blocks the calling thread,
/// while awaiting the handle uses a waker and does not block the polling
/// thread.
/// * **Completion probe** — [`TaskHandle::is_done`] reads an atomic flag set
/// after the worker publishes the result; it does not retrieve the value
/// (you still need [`TaskHandle::get`] for that).
///
/// # Examples
///
/// ```rust
/// use std::io;
///
/// use qubit_executor::executor::{
/// Executor,
/// ThreadPerTaskExecutor,
/// };
///
/// let executor = ThreadPerTaskExecutor;
/// let handle = executor.call(|| Ok::<i32, io::Error>(40 + 2));
///
/// // Blocks the current thread until the spawned thread completes.
/// let value = handle.get().expect("task should succeed");
/// assert_eq!(value, 42);
/// ```
;