SyncProducer

Struct SyncProducer 

Source
pub struct SyncProducer<T>
where T: Send + 'static + Debug + Clone,
{ /* 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>
where T: Send + 'static + Debug + Clone,

Source

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>()?;
producer.set(MyData { value: 42 })?; // blocks until value is sent and produced
Source

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>()?;
producer.set_with_timeout(MyData { value: 42 }, Duration::from_millis(100))?;
Source

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>()?;
match producer.try_set(MyData { value: 42 }) {
    Ok(()) => println!("Sent immediately"),
    Err(_) => println!("Channel full or runtime shutdown"),
}

Trait Implementations§

Source§

impl<T> Clone for SyncProducer<T>
where T: Send + 'static + Debug + Clone,

Source§

fn clone(&self) -> Self

Clone the producer to share across threads.

Multiple clones can set values concurrently.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Send for SyncProducer<T>
where T: Send + 'static + Debug + Clone,

Source§

impl<T> Sync for SyncProducer<T>
where T: Send + 'static + Debug + Clone,

Auto Trait Implementations§

§

impl<T> Freeze for SyncProducer<T>

§

impl<T> RefUnwindSafe for SyncProducer<T>

§

impl<T> Unpin for SyncProducer<T>

§

impl<T> UnwindSafe for SyncProducer<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more