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.
Trait Implementations§
Source§impl SessionWriter for DeferredWriter
impl SessionWriter for DeferredWriter
Source§fn send_audio<'life0, 'async_trait>(
&'life0 self,
data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send_audio<'life0, 'async_trait>(
&'life0 self,
data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn send_text<'life0, 'async_trait>(
&'life0 self,
text: String,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send_text<'life0, 'async_trait>(
&'life0 self,
text: String,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn send_tool_response<'life0, 'async_trait>(
&'life0 self,
responses: Vec<FunctionResponse>,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send_tool_response<'life0, 'async_trait>(
&'life0 self,
responses: Vec<FunctionResponse>,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn send_client_content<'life0, 'async_trait>(
&'life0 self,
turns: Vec<Content>,
turn_complete: bool,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send_client_content<'life0, 'async_trait>(
&'life0 self,
turns: Vec<Content>,
turn_complete: bool,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn send_video<'life0, 'async_trait>(
&'life0 self,
jpeg_data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send_video<'life0, 'async_trait>(
&'life0 self,
jpeg_data: Bytes,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn update_instruction<'life0, 'async_trait>(
&'life0 self,
instruction: String,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn update_instruction<'life0, 'async_trait>(
&'life0 self,
instruction: String,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn signal_activity_start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn signal_activity_start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn signal_activity_end<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn signal_activity_end<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl Freeze for DeferredWriter
impl !RefUnwindSafe for DeferredWriter
impl Send for DeferredWriter
impl Sync for DeferredWriter
impl Unpin for DeferredWriter
impl !UnwindSafe for DeferredWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].