pub struct EventEmitter<'a> {
pub ctx: &'a RequestContext,
pub queue: &'a dyn EventQueueWriter,
}Expand description
Ergonomic helper for emitting status and artifact events from an executor.
Caches task_id and context_id from the RequestContext so that every
event emission is a one-liner instead of a 7-line struct literal.
§Example
ⓘ
use a2a_protocol_server::executor_helpers::EventEmitter;
use a2a_protocol_types::task::TaskState;
use a2a_protocol_types::message::Part;
let emit = EventEmitter::new(ctx, queue);
emit.status(TaskState::Working).await?;
emit.artifact("result", vec![Part::text("hello")], None, Some(true)).await?;
emit.status(TaskState::Completed).await?;Fields§
§ctx: &'a RequestContextThe request context for this execution.
queue: &'a dyn EventQueueWriterThe event queue writer for this execution.
Implementations§
Source§impl<'a> EventEmitter<'a>
impl<'a> EventEmitter<'a>
Sourcepub fn new(ctx: &'a RequestContext, queue: &'a dyn EventQueueWriter) -> Self
pub fn new(ctx: &'a RequestContext, queue: &'a dyn EventQueueWriter) -> Self
Creates a new EventEmitter from the given context and queue.
Sourcepub async fn artifact(
&self,
id: &str,
parts: Vec<Part>,
append: Option<bool>,
last_chunk: Option<bool>,
) -> A2aResult<()>
pub async fn artifact( &self, id: &str, parts: Vec<Part>, append: Option<bool>, last_chunk: Option<bool>, ) -> A2aResult<()>
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if the task has been cancelled.
Auto Trait Implementations§
impl<'a> Freeze for EventEmitter<'a>
impl<'a> !RefUnwindSafe for EventEmitter<'a>
impl<'a> Send for EventEmitter<'a>
impl<'a> Sync for EventEmitter<'a>
impl<'a> Unpin for EventEmitter<'a>
impl<'a> UnsafeUnpin for EventEmitter<'a>
impl<'a> !UnwindSafe for EventEmitter<'a>
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
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request