Skip to main content

GracefulIpcChannel

Struct GracefulIpcChannel 

Source
pub struct GracefulIpcChannel<T = Vec<u8>> { /* private fields */ }
Expand description

IPC channel with graceful shutdown support

Implementations§

Source§

impl<T> GracefulIpcChannel<T>

Source

pub fn new(channel: IpcChannel<T>) -> Self

Create a new graceful IPC channel wrapper

Source

pub fn with_state(channel: IpcChannel<T>, state: Arc<ShutdownState>) -> Self

Create a new graceful IPC channel with a shared shutdown state

Source

pub fn create(name: &str) -> Result<Self>

Create a new IPC channel server with graceful shutdown

Source

pub fn connect(name: &str) -> Result<Self>

Connect to an existing IPC channel with graceful shutdown

Source

pub fn name(&self) -> &str

Get the channel name

Source

pub fn is_server(&self) -> bool

Check if this is the server end

Source

pub fn wait_for_client(&mut self) -> Result<()>

Wait for a client to connect (server only)

Source

pub fn state(&self) -> Arc<ShutdownState>

Get the shutdown state for sharing with other channels

Source

pub fn inner(&self) -> &IpcChannel<T>

Get a reference to the inner channel

Source

pub fn inner_mut(&mut self) -> &mut IpcChannel<T>

Get a mutable reference to the inner channel

Source

pub fn bind_affinity_thread(&self)

Bind the current thread as the affinity thread for this channel’s reentrancy-safe dispatch queue.

Call this once on the “main” (or named) thread that will drive pump_pending.

Source

pub fn submit_reentrant<F, R>(&self, f: F) -> Result<R>
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Submit f to run on the bound affinity thread in a deadlock-free way.

  • Caller is the affinity threadf executes inline.
  • Any other threadf is queued; the caller blocks until pump_pending processes it.

Parallel to Swift’s MainActor.assumeIsolated and C#’s SynchronizationContext.Send.

§Errors

Returns IpcError::Closed if the channel has been shut down or the affinity thread has been dropped.

Source

pub fn pump_pending(&self, budget: Duration) -> usize

Drain at most budget of pending work items on the current thread.

Call this from your host’s idle callback (Maya scriptJob idleEvent, Unity EditorApplication.update, Unreal FTSTicker, Blender bpy.app.timers, etc.) to let cross-thread submissions complete.

Returns the number of items processed.

Source§

impl GracefulIpcChannel<Vec<u8>>

Source

pub fn send_bytes(&mut self, data: &[u8]) -> Result<()>

Send raw bytes

Source

pub fn recv_bytes(&mut self) -> Result<Vec<u8>>

Receive raw bytes

Source§

impl<T: Serialize + DeserializeOwned> GracefulIpcChannel<T>

Source

pub fn send(&mut self, msg: &T) -> Result<()>

Send a typed message (serialized as JSON)

Source

pub fn recv(&mut self) -> Result<T>

Receive a typed message (deserialized from JSON)

Trait Implementations§

Source§

impl<T> GracefulChannel for GracefulIpcChannel<T>

Source§

fn shutdown(&self)

Signal the channel to shutdown Read more
Source§

fn is_shutdown(&self) -> bool

Check if the channel has been signaled to shutdown
Source§

fn drain(&self) -> Result<()>

Wait for all pending messages to be processed Read more
Source§

fn shutdown_timeout(&self, timeout: Duration) -> Result<()>

Shutdown with a timeout Read more

Auto Trait Implementations§

§

impl<T> Freeze for GracefulIpcChannel<T>

§

impl<T = Vec<u8>> !RefUnwindSafe for GracefulIpcChannel<T>

§

impl<T> Send for GracefulIpcChannel<T>
where T: Send,

§

impl<T> Sync for GracefulIpcChannel<T>
where T: Sync,

§

impl<T> Unpin for GracefulIpcChannel<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for GracefulIpcChannel<T>

§

impl<T = Vec<u8>> !UnwindSafe for GracefulIpcChannel<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> 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> IntoMetered for T

Source§

fn metered(self, metrics: Arc<ChannelMetrics>) -> MeteredSender<Self>

Wrap this sender with metrics tracking.
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> WithMetrics for T

Source§

fn with_metrics(self) -> MeteredWrapper<Self>

Wrap this channel with metrics tracking.
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