[−][src]Function rumq_client::eventloop
pub fn eventloop(
options: MqttOptions,
requests: impl Requests + 'static
) -> MqttEventLoop
Returns an object which encompasses state of the connection.
Use this to create an Stream
with stream()
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 resumend.
For a similar reason, requests are also initialized as part of this method to reuse same
request stream while retrying after the previous Stream
from stream()
method ends
let mut eventloop = eventloop(options, requests); loop { let mut stream = eventloop.stream(reconnection_options); 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
TODO: Remove mqttoptions
from state
to make sure that there is not chance of dirty opts