pub trait FlowControl: Send {
// Required methods
fn on_data_received(&mut self, channel_id: ChannelId, bytes: u32);
fn wait_for_send_credit(
&mut self,
channel_id: ChannelId,
bytes: u32,
) -> impl Future<Output = Result<()>> + Send;
fn consume_send_credit(&mut self, channel_id: ChannelId, bytes: u32);
}Expand description
Abstraction for stream flow control mechanism.
Different transports implement credit-based flow control differently:
- Stream transports (TCP, WebSocket): explicit
Message::Crediton the wire - SHM: shared atomic counters in the channel table (
ChannelEntry::granted_total)
This trait abstracts the mechanism while ChannelRegistry remains the source
of truth for stream lifecycle (routing, ordering, existence).
r[impl flow.channel.credit-based] r[impl flow.channel.all-transports]
Required Methods§
Sourcefn on_data_received(&mut self, channel_id: ChannelId, bytes: u32)
fn on_data_received(&mut self, channel_id: ChannelId, bytes: u32)
Called when we receive data on a channel (receiver side).
The implementation may grant credit back to the sender:
- Stream: queue a
Message::Creditto send - SHM: increment
ChannelEntry::granted_totalatomically
r[impl flow.channel.credit-grant]
Sourcefn wait_for_send_credit(
&mut self,
channel_id: ChannelId,
bytes: u32,
) -> impl Future<Output = Result<()>> + Send
fn wait_for_send_credit( &mut self, channel_id: ChannelId, bytes: u32, ) -> impl Future<Output = Result<()>> + Send
Wait until we have enough credit to send bytes on a channel (sender side).
- Stream: check
ChannelRegistry::outgoing_credit, wait on notify if insufficient - SHM: poll/futex wait on
granted_total - sent_total >= bytes
Returns Ok(()) when credit is available, Err if the channel is closed/invalid.
r[impl flow.channel.zero-credit]
Sourcefn consume_send_credit(&mut self, channel_id: ChannelId, bytes: u32)
fn consume_send_credit(&mut self, channel_id: ChannelId, bytes: u32)
Consume credit after sending data (sender side).
Called after successfully sending bytes on a channel.
- Stream: decrement
ChannelRegistry::outgoing_credit - SHM: increment local
sent_total
r[impl flow.channel.credit-consume]
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.