io-tether
A small library for defining I/O types which reconnect on errors.
Usage
To get started, add io-tether to your list of dependencies
= { = "0.3.0" }
Basics
The primary type exposed by this library is the Tether type. This
type is generic over three parameters:
-
I: The data supplied to attempt a connection to the io source. A socket address for TCP, a file name for Files, etc. This type must beClonesince an owned value is passed toIo::reconnecton each reconnect attempt. -
T: The I/O constructor. This is the type which produces the underlying connections. This is necessary to support more complicated io creation such as a QUIC connection, but for cases like TCP, this can mostly be ignored -
R: The resolver. This type will likely be generated by you in order to handle the buisness logic required for your application whenever a disconnect occurs. It drives the reconnect process and allows developers to inject arbirtary asynchronous code at various stages of the reconnection process
Example
Below is a simple example of a resolver implmentation that calls back to a channel whenever it detects a disconnect.
use Duration;
use ;
use ;
/// Custom resolver
async
Alternatives
-
stubborn-io similar, but uses synchronous callbacks and a duration iterator for retries
-
tokio-retry a more general purpose future retry library