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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! # SansIO Executor - Tokio-based Executor
//!
//! `sansio-executor` provides a tokio-based local executor for the sansio ecosystem.
//!
//! ## Features
//!
//! - **Tokio LocalSet**: Built on tokio's LocalSet for single-threaded task execution
//! - **CPU Pinning**: Pin executor threads to specific CPU cores
//! - **Thread Naming**: Name executor threads for debugging
//! - **Task Management**: Spawn, detach, and cancel tasks
//!
//! ## Quick Start
//!
//! ```toml
//! [dependencies]
//! sansio-executor = "0.0.7"
//! ```
//!
//! ```rust,no_run
//! use sansio_executor::LocalExecutorBuilder;
//!
//! LocalExecutorBuilder::default()
//! .run(async {
//! println!("Running on tokio!");
//! });
//! ```
//!
//! ## CPU Pinning
//!
//! ```rust,no_run
//! use sansio_executor::LocalExecutorBuilder;
//! use core_affinity::CoreId;
//!
//! LocalExecutorBuilder::new()
//! .name("my-executor")
//! .core_id(CoreId { id: 0 })
//! .run(async {
//! println!("Running on CPU core 0!");
//! });
//! ```
//!
//! ## Spawning Local Tasks
//!
//! ```rust,no_run
//! use sansio_executor::{LocalExecutorBuilder, spawn_local};
//!
//! LocalExecutorBuilder::default().run(async {
//! let task1 = spawn_local(async {
//! println!("Task 1");
//! 42
//! });
//!
//! let task2 = spawn_local(async {
//! println!("Task 2");
//! 100
//! });
//!
//! let result1 = task1.await.unwrap();
//! let result2 = task2.await.unwrap();
//!
//! println!("Results: {}, {}", result1, result2);
//! });
//! ```
//!
//! ## API
//!
//! The main exports are:
//!
//! - [`LocalExecutorBuilder`]: Builder for configuring and creating executors
//! - [`spawn_local()`]: Spawn a task on the current executor, returns a [`Task`]
//! - [`yield_local()`]: Yield to other tasks
//! - [`Task<T>`]: A handle to a spawned task, implements `Future<Output = Result<T, TaskError>>`
//! - [`TaskError`]: Error type returned when a task fails (panic or cancellation)
//!
//! ## Task Execution
//!
//! Tasks spawned with [`spawn_local()`] return a [`Task<T>`] handle that can be awaited:
//!
//! ```rust,no_run
//! use sansio_executor::{LocalExecutorBuilder, spawn_local};
//!
//! LocalExecutorBuilder::default().run(async {
//! let task = spawn_local(async { 42 });
//!
//! // Task implements Future<Output = Result<T, TaskError>>
//! match task.await {
//! Ok(result) => println!("Task completed: {}", result),
//! Err(e) => eprintln!("Task failed: {}", e),
//! }
//! });
//! ```
//!
//! ## Detaching Tasks
//!
//! Tasks can be detached to run in the background without awaiting them:
//!
//! ```rust,no_run
//! use sansio_executor::{LocalExecutorBuilder, spawn_local};
//!
//! LocalExecutorBuilder::default().run(async {
//! let task = spawn_local(async {
//! println!("Running in background");
//! });
//!
//! // Detach - task continues running even though we don't await it
//! task.detach();
//! });
//! ```
//!
//! ## Error Handling
//!
//! Tasks can fail if they panic or are cancelled/aborted. The [`TaskError`] type
//! wraps tokio's `JoinError` and provides error information.
pub use *;