Open slingamn opened 12 months ago
We should fix #100 as part of this work
Concurrent calls to Connect()
(or Reconnect()
) should be safe (only one should succeed). A Reconnect()
call that happens-before the first Connect()
call should probably just become a Connect()
.
Context: https://github.com/autobrr/autobrr/pull/1239#issuecomment-1804043932
I decided against some of the goals there (for example, being able to stop, reconfigure, and restart the connection is a non-goal now). I want to keep the linear lifecycle (
Connection
goes from stopped, to connecting, to connected, possibly to sleeping in between reconnections, and then finally to quit / perma-stopped), but with some changes:Connection
at any point in this lifecycle (probably need to add an exported enum describing the states)Connection
should be in a valid state before the first(*Connection).Connect
has completed (or before it has been called at all); no methods should panic on an out-of-order call hereLoop()
will still be provided as a compatibility alias but the preferred name for the new functionality (block untilQuit()
is called) will beWait()
QuitTimeout
after which we forcibly close the socket.) Multiple concurrentWait()
operations should be possible, thus making it safe toQuit()
and thenWait()
from any goroutine.