mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-08-17 00:20:46 +02:00
Add files via upload
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package robot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
reconnectInitial = 5 * time.Second
|
||||
reconnectMax = 60 * time.Second
|
||||
)
|
||||
|
||||
func waitReconnect(ctx context.Context, backoff *time.Duration) bool {
|
||||
if ctx.Err() != nil {
|
||||
return false
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return false
|
||||
case <-time.After(*backoff):
|
||||
if *backoff < reconnectMax {
|
||||
*backoff *= 2
|
||||
if *backoff > reconnectMax {
|
||||
*backoff = reconnectMax
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func bumpBackoff(backoff *time.Duration) {
|
||||
if *backoff < reconnectMax {
|
||||
*backoff *= 2
|
||||
if *backoff > reconnectMax {
|
||||
*backoff = reconnectMax
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user