Skip to main content

EventLoopHandle

Struct EventLoopHandle 

Source
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

Source

pub async fn send_command( &self, packet: CommandPacket, ) -> JdwpResult<ReplyPacket>

Send a command and wait for reply

§Errors

Returns a JdwpError if the event loop has shut down or the reply is lost before it arrives. Both cases name the reason the loop stopped when it recorded one.

Source

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.

Source

pub async fn try_recv_event(&self) -> Option<EventSet>

Try to receive an event (non-blocking)

Source

pub async fn recv_event(&self) -> Option<EventSet>

Wait for the next event (blocking)

Trait Implementations§

Source§

impl Clone for EventLoopHandle

Source§

fn clone(&self) -> EventLoopHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EventLoopHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> 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