pub struct HostedRpcChannel { /* private fields */ }Expand description
Per-dep channel handed to HostedRpcDep::build_stub on the worker side.
The stub holds this channel and calls HostedRpcChannel::call from
each of its method bodies; the channel takes care of dep-id routing,
serialization framing, and waiting for the parent’s reply.
Implementations§
Source§impl HostedRpcChannel
impl HostedRpcChannel
Sourcepub fn new(dep_id: String, transport: Arc<dyn HostedRpcTransport>) -> Self
pub fn new(dep_id: String, transport: Arc<dyn HostedRpcTransport>) -> Self
Construct a channel that targets the dep identified by
dep_id (a fully-qualified id) and uses the supplied transport.
Sourcepub fn dep_id(&self) -> &str
pub fn dep_id(&self) -> &str
The fully-qualified dep id this channel routes to. Stubs almost never need this directly, but it’s exposed for diagnostics and tests.
Sourcepub fn call(
&self,
method_idx: u32,
args: Vec<u8>,
) -> Result<Vec<u8>, HostedRpcError>
pub fn call( &self, method_idx: u32, args: Vec<u8>, ) -> Result<Vec<u8>, HostedRpcError>
Send one method call and block until the parent replies. args are
already-serialized bytes; the stub method body owns the choice of
codec.
Temporal invariant — only call this while a test body is actually
running. The transport assumes one
HostedRpc request/reply pair per worker subprocess is in flight
at a time and that the worker’s main IPC command loop is idle
(it only reads Provide* / RunTest between tests). Specifically:
- Do NOT call from
HostedRpcDep::build_stub— see that method’s docs for why. - Do NOT call from background threads or detached tasks that
outlive the test body — once the test returns the worker
sends
TestFinishedand the parent’s next message will be aProvide*/RunTest, which the transport’s read side would then misinterpret as a reply. - Do NOT call from
Drop/ destructor-style cleanup or any teardown hook that may fire after the test body has returned — that is just another form of “outside the test body” and has the same IPC-framing-desync risk as a detached background thread. - Stub calls from inside the test body — directly or transitively from helpers the test body awaits/blocks on — are the supported shape.