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

Download history 283/week @ 2025-03-15 22/week @ 2025-03-22 123/week @ 2025-03-29 9/week @ 2025-04-05 4/week @ 2025-04-12 97/week @ 2025-04-19 128/week @ 2025-04-26

239 downloads per month

MIT license

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.

No runtime deps