-
Notifications
You must be signed in to change notification settings - Fork 5
[2/9] docs: add Backend enum tests and documentation #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[2/9] docs: add Backend enum tests and documentation #106
Conversation
Consolidate the two separate GenServer implementations (async/tokio and threads) into a single implementation with a Backend enum parameter. Breaking change: start() now requires a Backend argument: - Backend::Async - tokio async tasks (default) - Backend::Blocking - tokio's blocking thread pool - Backend::Thread - dedicated OS thread This provides runtime flexibility without code duplication, allowing users to mix different execution backends in the same application. - Add Backend enum to gen_server.rs - Change start() signature to accept Backend parameter - Update all examples and tests - Remove thread-based example crates
Add 10 new tests covering: - Backend enum traits (Default, Copy, Clone, Debug, PartialEq, Eq) - All three backends handle call/cast correctly - Backend::Thread isolates blocking work from async runtime - Multiple backends can run concurrently with independent state - Backend::default() works in start()
Document each backend option with: - Comparison table showing execution model, best use cases, and limitations - Code examples for each backend - Detailed "When to Use" guide with advantages and avoid-when advice - Per-variant documentation with specific use cases
| /// - Should not compete with other blocking tasks | ||
| /// - Run CPU-intensive workloads | ||
| /// | ||
| /// Each GenServer gets its own thread, providing complete isolation from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not true: GenServer::start(Backend::Thread) uses GenServerHandle::new_on_thread which end's up creating a new Runtime (currently a tokio Runtime) in a dedicated OS thread. While this isolates it from other tasks in other threads, it still needs the async runtime. And I believe it currently needs some fine tuning and testing, as it is started via Runtime::new() which creates a multi_thread Runtime (probably unnecessary for this case) with all features enabled (which should be reviewed).
|
This and the previous PR confuses between
Both exist separately because even when their APIs are similar, the first one has some |
Summary
Add comprehensive tests and documentation for the Backend enum.
Tests (10 new tests)
Documentation
~300 lines
Dependencies
Test plan
🤖 Generated with Claude Code