[−][src]Struct twitchchat::Runner
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
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.pub async fn run<IO>(__arg0: Self, io: IO) -> Result<Status, Error> where
IO: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
[src]
IO: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
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
- An error if one was encountered while in operation
Ok(Status::Eof)
if it ran to completionOk(Status::Canceled)
if the associatedControl::stop
was called
Trait Implementations
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,