Skip to content

Conversation

@unbalancedparentheses
Copy link

Summary

Add comprehensive tests and documentation for the Backend enum.

Tests (10 new tests)

  • 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()

Documentation

  • Comparison table: execution model, best use cases, limitations
  • Code examples for each backend
  • "When to Use" guide with advantages and when to avoid

~300 lines

Dependencies

⚠️ Merge after PR #105

Test plan

  • All 26 tests pass

🤖 Generated with Claude Code

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
@unbalancedparentheses unbalancedparentheses changed the title test: add Backend enum tests and documentation [2/8] [2/9] docs: add Backend enum tests and documentation Jan 10, 2026
/// - Should not compete with other blocking tasks
/// - Run CPU-intensive workloads
///
/// Each GenServer gets its own thread, providing complete isolation from
Copy link
Collaborator

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).

@ElFantasma
Copy link
Collaborator

This and the previous PR confuses between tasks::GenServerHandle::start_on_thread() and threads::GenServer::start():

tasks::GenServerHandle::start_on_thread(): Runs async code in its own Runtime in a dedicated thread

threads::GenServer::start(): Runs sync code in a dedicated thread without any async Runtime.

Both exist separately because even when their APIs are similar, the first one has some async functions while the later does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants