pub struct SharedState { /* private fields */ }Expand description
Thread-safe key-value store for parallel agent coordination.
Scoped to a single ParallelAgent::run() invocation. All sub-agents
share the same Arc<SharedState> instance.
§Example
ⓘ
use adk_core::SharedState;
use std::sync::Arc;
use std::time::Duration;
let state = Arc::new(SharedState::new());
// Agent A publishes a workbook handle
state.set_shared("workbook_id", serde_json::json!("wb-123")).await?;
// Agent B waits for the handle
let handle = state.wait_for_key("workbook_id", Duration::from_secs(30)).await?;Implementations§
Sourcepub fn new() -> SharedState
pub fn new() -> SharedState
Creates a new empty SharedState.
Inserts a key-value pair. Notifies all waiters on that key.
§Errors
Returns SharedStateError::EmptyKey if key is empty.
Returns SharedStateError::KeyTooLong if key exceeds 256 bytes.
Returns the value for a key, or None if not present.
Sourcepub async fn wait_for_key(
&self,
key: &str,
timeout: Duration,
) -> Result<Value, SharedStateError>
pub async fn wait_for_key( &self, key: &str, timeout: Duration, ) -> Result<Value, SharedStateError>
Blocks until the key appears, or the timeout expires.
If the key already exists, returns immediately.
§Errors
Returns SharedStateError::Timeout if the timeout expires.
Returns SharedStateError::InvalidTimeout if timeout is outside [1ms, 300s].
Trait Implementations§
Source§fn default() -> SharedState
fn default() -> SharedState
Returns the “default value” for a type. Read more
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
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::RequestCreates a shared type from an unshared type.