pub struct DeferredWriter { /* private fields */ }Expand description
A [SessionWriter] wrapper that flushes pending context before user content.
Wraps an inner writer and drains a shared PendingContext buffer before
forwarding send_audio, send_text, or send_video calls. This ensures
model-role context turns arrive in the same burst as user content.
§When context is flushed
-
send_audio: Context is flushed assend_client_content(drained, false)immediately before the audio frame. Audio goes viarealtimeInput(different wire message), so they are two frames — but sent back-to-back with no gap. -
send_text: Context is flushed, then user text is sent. Both go viaclientContent, but as separate messages since the user text needsturn_complete: trueto trigger a model response. -
send_video: Same as audio — flush then forward.
§When context is NOT flushed
send_tool_response, update_instruction, send_client_content,
signal_activity_start/end, and disconnect do NOT trigger a flush.
These are either internal SDK operations or explicit user control — flushing
context before them would be surprising.
Implementations§
Source§impl DeferredWriter
impl DeferredWriter
Sourcepub fn new(inner: Arc<dyn SessionWriter>, pending: Arc<PendingContext>) -> Self
pub fn new(inner: Arc<dyn SessionWriter>, pending: Arc<PendingContext>) -> Self
Create a new deferred writer wrapping the given writer.
Sourcepub fn pending(&self) -> &Arc<PendingContext>
pub fn pending(&self) -> &Arc<PendingContext>
Get a reference to the shared pending context buffer.