pub struct EventLoopHandle { /* private fields */ }Expand description
Handle to the event loop for sending commands and receiving events.
This handle can be cloned to send commands from multiple tasks, but only ONE clone
should call recv_event() or try_recv_event() at a time. The event receiver is
wrapped in an Arc<Mutex<Receiver>> which allows sharing, but concurrent event
consumption from multiple tasks will lead to unpredictable behavior (events distributed
round-robin across consumers).
§Thread Safety
- Commands can be sent concurrently from multiple clones
- Events should be consumed from a single task/clone
§Example
// Good: Single event consumer
let handle1 = event_loop.clone();
let handle2 = event_loop.clone();
// Both can send commands
let _ = handle1.send_command(cmd1).await;
let _ = handle2.send_command(cmd2).await;
// Only one should consume events
while let Some(event) = handle1.recv_event().await {
// Process event
}Implementations§
Source§impl EventLoopHandle
impl EventLoopHandle
Sourcepub async fn send_command(
&self,
packet: CommandPacket,
) -> JdwpResult<ReplyPacket>
pub async fn send_command( &self, packet: CommandPacket, ) -> JdwpResult<ReplyPacket>
Sourcepub async fn issue(&self, packet: CommandPacket) -> JdwpResult<InFlight>
pub async fn issue(&self, packet: CommandPacket) -> JdwpResult<InFlight>
Hand a command to the loop and return as soon as it is queued — without waiting for its reply.
This is the half of send_command that PERF-1
(#100) needed, and adding it changes
nothing underneath: the loop already writes a command and returns without awaiting its answer, and
already correlates replies by packet id. The serialisation was in the shape of the only way to
ask — one call that issued and awaited — not in the transport. See InFlight.
§Errors
Returns a JdwpError if the event loop has shut down before the command could be queued. Note
what this does not promise: the command has been handed over, not written. It is written when
the loop next reaches handle_outgoing_command, and a write failure is reported to
InFlight::reply rather than here.
Sourcepub async fn try_recv_event(&self) -> Option<EventSet>
pub async fn try_recv_event(&self) -> Option<EventSet>
Try to receive an event (non-blocking)
Sourcepub async fn recv_event(&self) -> Option<EventSet>
pub async fn recv_event(&self) -> Option<EventSet>
Wait for the next event (blocking)
Trait Implementations§
Source§impl Clone for EventLoopHandle
impl Clone for EventLoopHandle
Source§fn clone(&self) -> EventLoopHandle
fn clone(&self) -> EventLoopHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more