pub struct SyncProducer<T>{ /* private fields */ }Expand description
Synchronous producer for records of type T.
Thread-safe, can be cloned and shared across threads. Values are moved (not cloned) through channels for zero-copy performance.
§Thread Safety
Multiple clones of SyncProducer<T> can be used concurrently from
different threads. Each set() operation is independent and thread-safe.
§Example
// Set value (blocks until sent)
producer.set(Temperature { celsius: 25.0 })?;
// Set with timeout
use std::time::Duration;
producer.set_with_timeout(
Temperature { celsius: 26.0 },
Duration::from_millis(100)
)?;
// Try to set (non-blocking)
match producer.try_set(Temperature { celsius: 27.0 }) {
Ok(()) => println!("Success"),
Err(_) => println!("Channel full, try later"),
}Implementations§
Source§impl<T> SyncProducer<T>
impl<T> SyncProducer<T>
Sourcepub fn set(&self, value: T) -> DbResult<()>
pub fn set(&self, value: T) -> DbResult<()>
Set the value, blocking until it can be sent.
This call will block the current thread until the value can be sent to the runtime thread. It’s guaranteed to deliver the value eventually unless the runtime thread has shut down.
§Errors
Returns DbError::RuntimeShutdown if the runtime thread has been detached.
Returns any error from the underlying produce() operation (e.g., record not registered,
buffer full, etc.).
§Example
use aimdb_core::AimDbBuilder;
use aimdb_sync::AimDbBuilderSyncExt;
use aimdb_tokio_adapter::TokioAdapter;
use std::sync::Arc;
let handle = AimDbBuilder::new()
.runtime(Arc::new(TokioAdapter))
.attach()?;
let producer = handle.producer::<MyData>("my_data")?;
producer.set(MyData { value: 42 })?; // blocks until value is sent and producedSourcepub fn set_with_timeout(&self, value: T, timeout: Duration) -> DbResult<()>
pub fn set_with_timeout(&self, value: T, timeout: Duration) -> DbResult<()>
Set the value with a timeout.
Attempts to send the value to the runtime thread and wait for produce completion,
blocking for at most timeout duration.
§Errors
Returns DbError::SetTimeout if the timeout expires before the value can be sent
or if waiting for the produce result exceeds the timeout.
Returns DbError::RuntimeShutdown if the runtime thread has been detached.
Returns any error from the underlying produce() operation.
§Example
use aimdb_core::AimDbBuilder;
use aimdb_sync::AimDbBuilderSyncExt;
use aimdb_tokio_adapter::TokioAdapter;
use std::sync::Arc;
use std::time::Duration;
let handle = AimDbBuilder::new()
.runtime(Arc::new(TokioAdapter))
.attach()?;
let producer = handle.producer::<MyData>("my_data")?;
producer.set_with_timeout(MyData { value: 42 }, Duration::from_millis(100))?;Sourcepub fn try_set(&self, value: T) -> DbResult<()>
pub fn try_set(&self, value: T) -> DbResult<()>
Try to set the value without blocking.
Attempts to send the value immediately. Returns an error if the channel is full or the runtime thread has shut down.
Note: This method returns immediately after sending to the channel, but does NOT
wait for the produce operation to complete. Use set() or set_with_timeout() if
you need to know whether the produce operation succeeded.
§Errors
Returns DbError::SetTimeout if the channel is full.
Returns DbError::RuntimeShutdown if the runtime thread has been detached.
§Example
use aimdb_core::AimDbBuilder;
use aimdb_sync::AimDbBuilderSyncExt;
use aimdb_tokio_adapter::TokioAdapter;
use std::sync::Arc;
let handle = AimDbBuilder::new()
.runtime(Arc::new(TokioAdapter))
.attach()?;
let producer = handle.producer::<MyData>("my_data")?;
match producer.try_set(MyData { value: 42 }) {
Ok(()) => println!("Sent immediately"),
Err(_) => println!("Channel full or runtime shutdown"),
}