pub struct CoreHandle { /* private fields */ }Expand description
Handle to a core’s reactor thread.
Provides lock-free communication with the core via SPSC queues and credit-based flow control for backpressure.
Implementations§
Source§impl CoreHandle
impl CoreHandle
Sourcepub fn spawn(config: CoreConfig) -> Result<Self, TpcError>
pub fn spawn(config: CoreConfig) -> Result<Self, TpcError>
Spawns a new core thread with the given configuration.
§Errors
Returns an error if the thread cannot be spawned.
Sourcepub fn spawn_with_operators(
config: CoreConfig,
operators: Vec<Box<dyn Operator>>,
) -> Result<Self, TpcError>
pub fn spawn_with_operators( config: CoreConfig, operators: Vec<Box<dyn Operator>>, ) -> Result<Self, TpcError>
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if the core thread is running.
Sourcepub fn events_processed(&self) -> u64
pub fn events_processed(&self) -> u64
Returns the number of events processed by this core.
Sourcepub fn outputs_dropped(&self) -> u64
pub fn outputs_dropped(&self) -> u64
Returns the number of outputs dropped due to a full outbox.
Sourcepub fn send(&self, message: CoreMessage) -> Result<(), TpcError>
pub fn send(&self, message: CoreMessage) -> Result<(), TpcError>
Sends a message to the core with credit-based flow control.
This method respects the backpressure configuration:
Block: Spins until credits available, then sendsDrop: Returns Ok but drops the message if no creditsError: Returns error if no credits available
§Errors
Returns an error if the inbox queue is full or credits exhausted (with Error strategy).
Sourcepub fn try_send(&self, message: CoreMessage) -> Result<(), TpcError>
pub fn try_send(&self, message: CoreMessage) -> Result<(), TpcError>
Tries to send a message without blocking.
Returns Err if no credits available or queue is full.
Does not block regardless of overflow strategy.
§Errors
Returns an error if credits exhausted or queue full.
Sourcepub fn send_event(&self, event: Event) -> Result<(), TpcError>
pub fn send_event(&self, event: Event) -> Result<(), TpcError>
Sends an event to the core with credit-based flow control.
§Errors
Returns an error if the inbox queue is full or backpressure applies.
Sourcepub fn try_send_event(&self, event: Event) -> Result<(), TpcError>
pub fn try_send_event(&self, event: Event) -> Result<(), TpcError>
Tries to send an event without blocking.
§Errors
Returns an error if credits exhausted or queue full.
Sourcepub fn poll_outputs(&self, max_count: usize) -> Vec<Output>
pub fn poll_outputs(&self, max_count: usize) -> Vec<Output>
Polls the outbox for outputs.
Returns up to max_count outputs.
§Note
This method allocates memory. For zero-allocation polling, use
poll_outputs_into or poll_each instead.
Sourcepub fn poll_outputs_into(
&self,
buffer: &mut Vec<Output>,
max_count: usize,
) -> usize
pub fn poll_outputs_into( &self, buffer: &mut Vec<Output>, max_count: usize, ) -> usize
Polls the outbox for outputs into a pre-allocated buffer (zero-allocation).
Outputs are appended to buffer. Returns the number of outputs added.
The buffer should have sufficient capacity to avoid reallocation.
§Example
let mut buffer = Vec::with_capacity(1024);
// First poll - fills buffer
let count1 = core_handle.poll_outputs_into(&mut buffer, 100);
// Process outputs...
for output in &buffer[..count1] {
process(output);
}
// Clear and reuse buffer for next poll (no allocation)
buffer.clear();
let count2 = core_handle.poll_outputs_into(&mut buffer, 100);Sourcepub fn poll_each<F>(&self, max_count: usize, f: F) -> usize
pub fn poll_each<F>(&self, max_count: usize, f: F) -> usize
Polls the outbox with a callback for each output (zero-allocation).
Processing stops when:
max_countoutputs have been processed- The outbox becomes empty
- The callback returns
false
Returns the number of outputs processed.
§Example
// Process outputs without any allocation
let count = core_handle.poll_each(100, |output| {
match output {
Output::Event(event) => handle_event(event),
_ => {}
}
true // Continue processing
});Sourcepub fn poll_output(&self) -> Option<Output>
pub fn poll_output(&self) -> Option<Output>
Polls a single output from the outbox.
Sourcepub fn outbox_len(&self) -> usize
pub fn outbox_len(&self) -> usize
Returns the number of pending outputs in the outbox.
Sourcepub fn is_backpressured(&self) -> bool
pub fn is_backpressured(&self) -> bool
Returns true if backpressure is currently active.
Sourcepub fn available_credits(&self) -> usize
pub fn available_credits(&self) -> usize
Returns the number of available credits.
Sourcepub fn max_credits(&self) -> usize
pub fn max_credits(&self) -> usize
Returns the maximum credits configured.
Sourcepub fn credit_metrics(&self) -> &CreditMetrics
pub fn credit_metrics(&self) -> &CreditMetrics
Returns the credit metrics.
Trait Implementations§
Source§impl Debug for CoreHandle
impl Debug for CoreHandle
Auto Trait Implementations§
impl Freeze for CoreHandle
impl !RefUnwindSafe for CoreHandle
impl Send for CoreHandle
impl Sync for CoreHandle
impl Unpin for CoreHandle
impl !UnwindSafe for CoreHandle
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.