[−][src]Struct rumqttc::EventLoop
Complete state of the eventloop
Fields
options: MqttOptions
Options of the current mqtt connection
state: MqttState
Current state of the connection
requests: Throttle<R>
Request stream
Implementations
impl<R: Requests> EventLoop<R>
[src]
pub async fn new(options: MqttOptions, requests: R) -> EventLoop<R>
[src]
Returns an object which encompasses state of the connection.
Use this to create a Stream
with connect().await?
method and poll it with tokio.
The choice of separating MqttEventLoop
and stream
methods is to get access to the
internal state and mqtt options after the work with the Stream
is done or stopped.
This is useful in scenarios like shutdown where the current state should be persisted or
during reconnection when the state from last disconnection should be resumed.
For a similar reason, requests are also initialized as part of this method to reuse same
request stream while retrying after the previous Stream
has stopped
let mut eventloop = eventloop(options, requests); loop { let mut stream = eventloop.connect(reconnection_options).await.unwrap(); while let Some(notification) = stream.next().await() {} }
When mqtt stream
ends due to critical errors (like auth failure), user has a choice to
access and update options
, state
and requests
.
For example, state and requests can be used to save state to disk before shutdown.
Options can be used to update gcp iotcore password
pub fn set_reconnection_delay(&mut self, delay: Duration)
[src]
pub fn take_cancel_handle(&mut self) -> Option<Sender<()>>
[src]
pub async fn poll<'_>(
&'_ mut self
) -> Result<(Option<Incoming>, Option<Outgoing>), ConnectionError>
[src]
&'_ mut self
) -> Result<(Option<Incoming>, Option<Outgoing>), ConnectionError>
Next notification or outgoing request
This method used to return only incoming network notification while silently looping through
outgoing requests. Internal loops inside async functions are risky. Imagine this function
with 100 requests and 1 incoming packet. If this Stream
(which internally loops) is
selected with other streams, can potentially do more internal polling (if the socket is ready)
impl<R: Requests> EventLoop<R>
[src]
pub async fn connect_or_cancel<'_>(&'_ mut self) -> Result<(), ConnectionError>
[src]
pub async fn connect<'_>(&'_ mut self) -> Result<(), ConnectionError>
[src]
This stream internally processes requests from the request stream provided to the eventloop while also consuming byte stream from the network and yielding mqtt packets as the output of the stream. This function (for convenience) includes internal delays for users to perform internal sleeps between re-connections so that cancel semantics can be used during this sleep
Auto Trait Implementations
impl<R> !RefUnwindSafe for EventLoop<R>
impl<R> Send for EventLoop<R>
impl<R> Sync for EventLoop<R> where
R: Sync,
R: Sync,
impl<R> Unpin for EventLoop<R>
impl<R> !UnwindSafe for EventLoop<R>
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>,