#tcp-connection #connector #tokio #networking #async-networking

schmoozer

A simple abstraction over a retryable async operation

2 releases

0.1.2 Mar 1, 2024
0.1.1 Feb 29, 2024

#2162 in Network programming

Download history 241/week @ 2024-02-26 22/week @ 2024-03-04 2/week @ 2024-03-11 51/week @ 2024-03-18 29/week @ 2024-04-01

85 downloads per month

0BSD license

12KB
147 lines

schmoozer

A simple abstraction over a retryable async operation, such as establishing a TCP connection.


lib.rs:

schmoozer is intended to be used as an async (re)connector. It consists of two parts:

  • The Connector trait is implemented by applications/libraries that need to run retryable connection loops.
  • [run()] is a function that takes in a Connector implementation, and attempts to establish a connection, delaying and retrying on failures that the callback reports as retriable, and calls the [Connector::run()] trait method once a connection has been successfully been established.

Perhaps paradoxically the [run()] function does not itself actually attemtp to establish any connections -- it relies on the Connector trait to implement the means to establish connections.

The "good path" overall flow of the connector loop is to call the connect() method. If it is successful, call the run() method, passing along the newly allocated connection. The main application logic relating to the connection should called from this method.

The primary purpose of the connector concerns the "failure path": If the connect() method encounters a failure it can choose to signal to back to the connector loop that the error is "retryable", in which case the retry_delay() method is called to determine if the connector loop should retry (and implement a delay before returning instructions to do so).

Likewise, the run() method returns its Result<(), Self::Error> wrapped in a ControlFlow::Continue(_) to indicate that the connector look should reconnect, while ControlFlow::Break(_) signals that a fatal error occured and the connect loop should terminate.

Dependencies

~0.3–12MB
~96K SLoC