Expand description
§About
async-nng is a small wrapper that uses the
async-channel crate alongside the
nng crate to provide types that provide async-await
semantics around send and receive operations on an NNG socket.
The futures that are constructed by the wrapper types in this crate directly utilize the
nng::Aio framework, and do not use any
spawn_blocking, unblock, or send any data to a backing threadpool in order to work. This
makes it extremely useful to use in scenarios where the
blocking crate or the tokio equivalent
(spawn_blocking) are undesirable.
§Installing
$ cargo add async-nng§Runtime Selection
This crate should work with any of tokio, async-std, or smol. The tests in this crate use
smol purely to save on the number of dev-dependencies, but there are no types used within
this crate itself that rely on spawning tasks or any executor-specific API.
§AsyncContext and AsyncSocket
The two primary types provided by this crate are AsyncContext and AsyncSocket. In almost
all instances, one should prefer contexts to sockets when writing asynchronous and concurrent
programs. See the documentation for AsyncContext for more information.
AsyncSocket is provided as well for those using raw-mode sockets or who otherwise cannot
take advantage of contexts. Unlike contexts which borrow the underlying nng::Socket,
AsyncSocket itself is an owning type and owns the socket. An AsyncSocket::into_inner is
provided so that the original socket type can be recovered if there is an error or some other
reason to get access to the underlying socket.
§Acknowledgements
Thanks to @neachdainn in the NNG discord (and maintainer of the nng crate) for helping me
in constructing the MVP for async-await semantics wrapping the nng crate.
Structs§
- Async
Context - A wrapper type around
Contextto enable async-await send and receive operations. - Async
Socket - A wrapper type around
Socketto enable async-await send and receive operations.