| commit | 0988dcb8bb356b1844aa04a82f7571bd81b63ec7 | [log] [tgz] |
|---|---|---|
| author | Viktoriia Kovalova <vkovalova@google.com> | Tue May 28 12:44:37 2024 +0000 |
| committer | Viktoriia Kovalova <vkovalova@google.com> | Tue May 28 13:02:41 2024 +0000 |
| tree | 0ebf1cbe148a67ad9b109b9a07851d6ebd5dff24 | |
| parent | 3b603739415fee5b383fa9d67cafc2b682ac141e [diff] |
Import 'want' crate Request Document: go/android-rust-importing-crates For CL Reviewers: go/android3p#cl-review For Build Team: go/ab-third-party-imports Bug: 339186353 Test: m libwant Change-Id: I1cc590142d349aa057c9b958b7129e129e468e17
A Futures channel-like utility to signal when a value is wanted.
Futures are supposed to be lazy, and only starting work if Future::poll is called. The same is true of Streams, but when using a channel as a Stream, it can be hard to know if the receiver is ready for the next value.
Put another way, given a (tx, rx) from futures::sync::mpsc::channel(), how can the sender (tx) know when the receiver (rx) actually wants more work to be produced? Just because there is room in the channel buffer doesn't mean the work would be used by the receiver.
This is where something like want comes in. Added to a channel, you can make sure that the tx only creates the message and sends it when the rx has poll() for it, and the buffer was empty.
want is provided under the MIT license. See LICENSE.