7 releases (4 breaking)
new 0.5.0 | Apr 30, 2025 |
---|---|
0.4.0 | Apr 22, 2025 |
0.3.1 | Mar 29, 2025 |
0.2.1 | Mar 17, 2025 |
0.1.1 | Mar 15, 2025 |
#574 in Asynchronous
239 downloads per month
28KB
364 lines
A typical architecture of network service is that after receiving a request, the network tasks dispatch it to the business tasks according to some fields. In this way, requests for the same content can be dispatched in the same task to avoid shared state or locking. This tokio tutorial gives detailed description.
The same is true in tonic
's gRPC server. The dispatch of requests
from network tasks to the business task has a pattern. This crate is
an abstraction of this pattern to simplify the repetitive work in
the application.
Read the documentation for more detail.
lib.rs
:
A typical architecture of network service is that after receiving a request, the network tasks dispatch it to the business tasks according to some fields. In this way, requests for the same content can be dispatched in the same task to avoid shared state or locking. This tokio tutorial gives detailed description.
The same is true in tonic
's gRPC server. The dispatch of requests
from network tasks to the business task has a pattern. This crate is
an abstraction of this pattern to simplify the repetitive work in
the application.
Examples
This library is a bit difficult to get started with. See the DictService service examples in async mode or sync mode, before the API documentation.
Async vs Sync
The business jobs can run in async or sync mode.
The tokio tutorial talks about the async mode. The business jobs run as tokio-tasks above the tokio runtime:
network +--+ +--+ +--+ channels +--+ +--+ +--+ business
tasks | | | | | | <----------> | | | | | | tasks*
+--+ +--+ +--+ +--+ +--+ +--+
tokio +----------------------------------------+
runtime | |
+----------------------------------------+
+---+ +---+ +---+
threads | | | | ... | |
+---+ +---+ +---+
If your business jobs contains no async code, then they can also run as native threads:
network +--+ +--+ +--+ +---+ +---+ +---+ business
tasks | | | | | | | | | | | | threads*
+--+ +--+ +--+ | | | | | |
tokio +------------+ channels | | | | | |
runtime | | <----------> | | | | | |
+------------+ | | | | | |
+---+ +---+ | | | | | |
threads | |... | | | | | | | |
+---+ +---+ +---+ +---+ +---+
This crate supports both modes.