Crate ump_server
source ·Expand description
ump-server is an abstraction on top of ump
that is used to hide
boilerplate code used to implement intra-process message passing servers.
Dispatch loop
The core functionality of ump-server is a dispatch loop, whose role it is to pull messages off the message queue and pass them to the application-supplied message handler.
There are two different ways to run the dispatcher loop: On a non-async
thread or as an async task. The former is launched using
thread::spawn()
and the latter task::spawn()
(only available using
the tokio
feature).
The spawn()
functions return a tuple containing a Client
(that can be
used to send pass messages to the server) and a JoinHandle
that can be
used to wait for the dispatch loop thread/task to terminate (and retreive
its return value).
The returned JoinHandle
will, once joined, return an Option<RV>
.
If this is None
the server was terminated because all the Client
endpoints were dropped. If this is Some(RV)
the server was terminated
because a callback requested its termination by returning
ControlFlow::Break(RV)
.
There are two ways to terminate the dispatch loop:
- The message processing handler returns
ControlFlow::Break(RV)
(rather thanControlFlow::Continue(())
). This would cause the thread/task to returnSome(RV)
. - The message queue is empty and all the associated
Client
s have been released. This would cause the thread to returnNone
.
Application message handlers
Message handlers are implemented using the thread::Handler
trait (for
the threaded dispatch loop) and task::Handler
(for the async dispatch
loop).
Re-exports
pub use thread::spawn as spawn_thread;
pub use thread::Handler as ThreadedHandler;
pub use task::spawn as spawn_task;
pub use task::Handler as AsyncHandler;
pub use ump;
Modules
- task
tokio
ump server running in an async task. - ump server running on a thread.
Structs
- Representation of a clonable client object that can issue requests to
Server
objects. - Object used to respond to requests that have been received by a
Server
. - A weak client reference that can be upgraded to a
Client
as long as otherClient
objects till exist.
Enums
- Module-specific error codes.
Functions
Attribute Macros
- async_trait
tokio