faucet
deadqueue::limited::Queue
+tokio_util::sync::CancellationToken
=faucet::Faucet
Faucet
is a back-pressured MPMC queue that can be drained after signaling completion.
Once completion is signaled, no more items can be added to the queue and only the remaining items in the queue can be drained. This property is useful for ensuring all items that were already queued are processed before shutting down.
You can freely clone()
a Facuet
to easily share it between asynchronous tasks for your producers and consumers. You don't need to wrap Faucet
in an additional Arc
since Faucet
internally uses an Arc<deadqueue::limited::Queue<T>>
Example
You can clone this repo and run this example with cargo run --example sigint
.
use Error;
use Duration;
use sleep;
use ;
use CancellationToken;
use Faucet;
async
An example run:
got #1 (4 items waiting)
got #2 (5 items waiting)
^Cdrain #3 (5 items waiting)
drain #4 (4 items waiting)
drain #5 (3 items waiting)
drain #6 (2 items waiting)
drain #7 (1 items waiting)
drain #8 (0 items waiting)
done
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.