Skip to main content

StreamEmitter

Struct StreamEmitter 

Source
pub struct StreamEmitter { /* private fields */ }
Expand description

Event emitter for ProcessRunner events

Provides on(), once(), off(), and emit() methods similar to Node.js EventEmitter.

Implementations§

Source§

impl StreamEmitter

Source

pub fn new() -> Self

Create a new event emitter

Source

pub async fn on<F>(&self, event: EventType, listener: F)
where F: Fn(EventData) + Send + Sync + 'static,

Register a listener for an event

§Arguments
  • event - The event type to listen for
  • listener - The callback function to invoke
§Example
emitter.on(EventType::Stdout, |data| {
    if let EventData::String(s) = data {
        println!("Got stdout: {}", s);
    }
});
Source

pub async fn once<F>(&self, event: EventType, listener: F)
where F: Fn(EventData) + Send + Sync + 'static,

Register a one-time listener for an event

The listener will be removed after it is invoked once.

Source

pub async fn emit(&self, event: EventType, data: EventData)

Emit an event to all registered listeners

§Arguments
  • event - The event type to emit
  • data - The event data to pass to listeners
Source

pub async fn off(&self, event: EventType)

Remove all listeners for an event

§Arguments
  • event - The event type to clear listeners for
Source

pub async fn listener_count(&self, event: &EventType) -> usize

Get the number of listeners for an event

Source

pub async fn remove_all_listeners(&self)

Remove all listeners for all events

Trait Implementations§

Source§

impl Debug for StreamEmitter

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for StreamEmitter

Source§

fn default() -> Self

Returns the “default value” for a type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.