pub struct RuntimeBridge { /* private fields */ }Expand description
Worker thread + private current-thread Tokio runtime used to drive async work off the caller’s runtime.
See the crate-level docs for the design rationale. Construct with
RuntimeBridge::new; submit work with RuntimeBridge::block_on.
Implementations§
Source§impl RuntimeBridge
impl RuntimeBridge
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Spawn a worker thread with a private current-thread Tokio runtime.
Returns the worker’s io::Error if the OS refuses the thread spawn.
The thread name is heddle-runtime-bridge so it’s identifiable in
stack traces and process listings; pick a more specific wrapper at
the call site if you need per-consumer naming.
Sourcepub fn with_thread_name(thread_name: impl Into<String>) -> Result<Self>
pub fn with_thread_name(thread_name: impl Into<String>) -> Result<Self>
Same as RuntimeBridge::new but uses a custom worker thread name.
Sourcepub fn block_on<F, T>(&self, future: F) -> Result<T, BridgeError>
pub fn block_on<F, T>(&self, future: F) -> Result<T, BridgeError>
Run future on the worker’s runtime and block the caller until it
completes, returning the future’s output or a BridgeError when
the worker cannot deliver a reply.
future must be Send + 'static; compose it from owned data
(Arc clones, owned String keys, serialized bodies), not borrows
of &self.
§Errors
BridgeError::WorkerDeadwhen the worker thread has terminated (its receive channel was dropped). Subsequent calls will keep returning this error; the bridge cannot recover.BridgeError::ResponseLostwhen the worker accepted the task but no reply arrived — the future panicked, or the worker’s runtime was dropped while the task was in flight. The bridge itself remains usable; other in-flight callers are unaffected.