The feature-rich, portable async channel library > crates.io > docs.rs
Why use Postage?
- Includes a rich set of channels.
- Works with any executor.
- Currently regressions are written for
tokio
andasync-std
.
- Currently regressions are written for
- Throughly tested.
- Channels have full unit test coverage, and integration test coverage with multiple async executors.
- Includes built-in Stream and Sink combinators.
- Sinks can be chained and filtered.
- Streams can be chained, filtered, mapped, and merged.
- Sinks and streams can log their values, for easy app debugging.
Postage is in beta quality. The functionality is implemented and has unit/integration test coverage. But it needs to be tested on more hardware, and more operating systems.
Channels
postage::mpsc
Postage includes a fixed-capacity multi-producer, single-consumer channel. The producer can be cloned, and the sender task is suspended if the channel becomes full.
postage::broadcast
The broadcast channel provides multi-sender, multi-receiver message dispatch. All receivers are sent every message. The channel has a fixed capacity, and senders are suspended if the buffer is filled.
When a receiver is cloned, both receivers will be sent the same series of messages.
Senders also provide a subscribe()
method which creates a receiver that will observe all messages sent after the call to subscribe.
postage::watch
Watch channels can be used to asynchronously transmit state. When receivers are created, they immediately recieve an initial value. They will also recieve new values, but are not guaranteed to recieve every value.
Values transmitted over watch channels must implement Default. A simple way to achieve this is to transmit Option<T>
.
postage::oneshot
Oneshot channels transmit a single value between a sender and a reciever. Neither can be cloned. If the sender drops, the receiver recieves a None
value.
postage::barrier
Barrier channels can be used to synchronize events, but do not transmit any data. When the sender is dropped (or tx.send(())
is called), the receiver is awoken. This can be used to asynchronously coordinate actions between tasks.
Benchmarks
Benchmarks of postage channels, and comparable async-std/tokio channels.
send/recv
measures the total time to send and receive an item.send full
measures the time to send an item and get aPoll::Pending
value on a full channel.recv empty
measures the time to get aPoll::Pending
value on an empty channel.
All benchmarks were taken with criterion and are in the benches
directory.
Package | Channel | send/recv | send full | recv empty |
---|---|---|---|---|
mpsc | postage | 66ns | 44ns | 47ns |
mpsc | tokio | 128ns (+90%) | 1ns | 31ns |
mpmc queue | async_std | 40ns (+65%) | 9ns | 10ns |
- | ||||
broadcast | postage | 140ns | 8ns | 8ns |
broadcast | tokio | 88ns (-38%) | 49ns | 39ns |
- | ||||
watch | postage | 92ns | - | 7ns |
watch | tokio | 74ns (-20%) | - | 75ns |