pub struct PingTracker { /* private fields */ }
Available on crate feature ping only.
Expand description

A simple type to track PINGs and if you should PONG

This requires the ping feature to be enabled

If either sync or parking_lot features are also enabled, then this type is safe to send to other threads

use twitch_message::PingTracker;
// create a new tracker, the `threshold` is used to determine when a connection is dead/stale.
let pt = PingTracker::new(std::time::Duration::from_secs(10 * 60));

// in some loop
// if its been a while (such as if you have a way to keep track of time)
if pt.probably_timed_out() {
    // we should reconnect
    return Err("timed out".into());
}

// this might block for a while
let msg = read_message();
// update the tracker
pt.update(&msg);

// check to see if you should reply.
// this returns a message you can write to your sink
if let Some(pong) = pt.should_pong() {
    io_sink.encode_msg(pong)?;
}

Implementations§

Create a new PingTracker with a ‘timeout’ duration

Get the ‘timeout’ duration

Update the tracker with this message

Determines whether you should PONG

This returns the message you should encode

Determines if the timeout threshold has been reached

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.