2 releases
0.1.1 | Sep 27, 2024 |
---|---|
0.1.0 | Jun 26, 2024 |
#1106 in Asynchronous
97 downloads per month
Used in 8 crates
(2 directly)
28KB
611 lines
SPSC Byte Channel
A single producer, single consumer asynchronous byte channel. The ByteReader
and ByteWriter
endpoints of the channel implement the Tokio tokio::io::AsyncRead
and tokio::io::AsyncWrite
traits respectively.
Running Cooperatively
Currently, types outside of of the Tokio crate cannot efficiently take part in the Tokio co-operative
yielding mechanism. To work around this, the byte channels have an optional cooperation mechanism of
their own that is enabled by the coop
feature flag.
To use the cooperation mechanism, wrap any top level task futures with RunWithBudget
. The extension
trait BudgetedFutureExt
adds methods to all futures to allocated a budget for the task. The budget is
shared between all byte channels within that future.
Whenever any of those channels makes progress it will consume a unit of budget. A channel that exhausts the budget will reset the budget and immediately yield to the runtime (after rescheduling itself).
Dependencies
~3.5–9.5MB
~91K SLoC