Skip to content

Commit 81e26d4

Browse files
committed
Improve docs
1 parent 0511df1 commit 81e26d4

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

relay-threading/src/lib.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
//! # Relay Threading
22
//!
3-
//! This module provides threading abstractions for Relay, offering a set of utilities for managing
4-
//! asynchronous work. It includes a thread-based asynchronous task pool, a flexible builder for
5-
//! configuring pool parameters (thread naming, panic handling, concurrency limits), and mechanisms for
6-
//! multiplexing tasks across dedicated threads with built-in panic recovery.
7-
//!
8-
//! ## Features
9-
//!
10-
//! - **AsyncPool**: A thread-based asynchronous pool for executing futures concurrently on dedicated threads.
11-
//! - **AsyncPoolBuilder**: A configurable builder to construct an [`AsyncPool`] with custom settings,
12-
//! including thread naming, panic handlers (for both threads and tasks), custom spawn handlers, and
13-
//! concurrency limits.
14-
//! - **Multiplexed Execution**: A task multiplexer that drives a collection of asynchronous tasks while
15-
//! respecting a specified concurrency limit. It handles panics gracefully via an optional panic callback.
16-
//! - **Custom Thread Spawning**: Supports customized thread creation, allowing usage of system defaults or
17-
//! custom configurations through a provided spawn handler.
3+
//! This module provides a robust threading framework for Relay, designed to efficiently manage and execute
4+
//! asynchronous workloads. At its core is a thread-based asynchronous task pool that offers:
5+
//!
6+
//! - **Flexible Configuration**: Fine-tune thread counts, naming patterns, panic handling strategies,
7+
//! and concurrency limits through a builder pattern.
8+
//! - **Task Multiplexing**: Distribute tasks across dedicated worker threads.
9+
//! - **Panic Recovery**: Built-in mechanisms to gracefully handle and recover from panics, both at the
10+
//! thread and individual task level
11+
//! - **Tokio Integration**: Seamlessly integrates with Tokio runtime for async task execution
12+
//!
13+
//! ## Concurrency Model
14+
//!
15+
//! The pool maintains a set of dedicated worker threads, each capable of executing multiple async tasks
16+
//! concurrently up to a configurable limit. This architecture ensures efficient resource utilization
17+
//! while preventing any single thread from becoming overwhelmed.
18+
//!
19+
//! The pool maintains a bounded queue with a capacity of twice the number of worker threads. This
20+
//! design allows new tasks to be queued while existing ones are being processed, ensuring smooth
21+
//! task handoff between producers and consumers. The bounded nature of the queue provides natural
22+
//! backpressure - when workers are overwhelmed, task submission will block until capacity becomes
23+
//! available, preventing resource exhaustion.
1824
//!
1925
//! ## Modules
2026
//!

relay-threading/src/multiplexing.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,16 @@ where
169169

170170
#[cfg(test)]
171171
mod tests {
172-
use super::*;
173-
use futures::{future::BoxFuture, FutureExt};
174172
use std::sync::atomic::AtomicBool;
175173
use std::sync::{
176174
atomic::{AtomicUsize, Ordering},
177175
Arc, Mutex,
178176
};
179177

178+
use futures::{future::BoxFuture, FutureExt};
179+
180+
use super::*;
181+
180182
fn future_with(block: impl FnOnce() + Send + 'static) -> BoxFuture<'static, ()> {
181183
let fut = async {
182184
// Yield to allow a pending state during polling.

relay-threading/src/pool.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,23 @@ where
192192

193193
#[cfg(test)]
194194
mod tests {
195-
use crate::builder::AsyncPoolBuilder;
196-
use crate::{AsyncPool, Thread};
197-
use futures::future::BoxFuture;
198-
use futures::FutureExt;
199195
use std::future::Future;
200196
use std::sync::atomic::AtomicBool;
201197
use std::sync::{
202198
atomic::{AtomicUsize, Ordering},
203199
Arc,
204200
};
205201
use std::time::{Duration, Instant};
202+
203+
use futures::future::BoxFuture;
204+
use futures::FutureExt;
206205
use tokio::runtime::Runtime;
207206
use tokio::sync::Semaphore;
208207
use tokio::{runtime::Handle, time::sleep};
209208

209+
use crate::builder::AsyncPoolBuilder;
210+
use crate::{AsyncPool, Thread};
211+
210212
struct TestBarrier {
211213
semaphore: Arc<Semaphore>,
212214
count: u32,

0 commit comments

Comments
 (0)