[][src]Struct twitchchat::Runner

pub struct Runner { /* fields omitted */ }

The runner is the main "event loop" of this crate.

It is created with a Dispatcher. It returns the new runner and the Control type.

Once you're ready to start reading from the Reader and processing Writes you should call Runner::run.

Returns

  • A future which resolves to a Status once the Runner has finished.

Interacting with the Runner is done via the Control type.

Example

use twitchchat::{Dispatcher, Status, Runner, RateLimit};
// make a dispatcher
let dispatcher = Dispatcher::new();
// do stuff with the dispatcher (its clonable)
// ..

// create a new runner
let (runner, control) = Runner::new(dispatcher, RateLimit::default());

// spawn a task that kills the runner after some time
let ctl = control.clone();
spawn(async move {
    // pretend some time has passed
    ctl.stop()
});

// run, blocking the task.
// you can spawn this in a task and await on that join handle if you prefer
match runner.run(conn).await {
    // for the doc test
    Ok(Status::Canceled) => { assert!(true) }
    Ok(Status::Eof) => { panic!("eof") }
    Ok(Status::Timeout) => { panic!("timeout") }
    Err(err) => { panic!("{}", err) }
};

Methods

impl Runner[src]

pub fn new(dispatcher: Dispatcher, rate_limit: RateLimit) -> (Self, Control)[src]

This is supported on feature="tokio" only.

Create a new client runner with this Dispatcher

Returns

The Runner and a Control type

pub async fn run<IO>(__arg0: Self, io: IO) -> Result<Status, Error> where
    IO: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static, 
[src]

This is supported on feature="tokio" only.

Run to completion, dispatching messages to the subscribers.

This returns a future. You should await this future at the end of your code to keep the runtime active until the client closes.

Interacting with the runner

You can interact with the runner via the Control type returned by Runner::new.

To stop this early, you can use the Control::stop method.

To get a writer, you can use the Control::writer method.

Returns after resolving the future

Trait Implementations

impl Debug for Runner[src]

Auto Trait Implementations

impl !RefUnwindSafe for Runner

impl Send for Runner

impl Sync for Runner

impl Unpin for Runner

impl !UnwindSafe for Runner

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.