feat: complete cmpp platform phases 0-5

This commit is contained in:
hectorzhao
2026-07-01 13:22:04 +08:00
parent 824a8b334f
commit ee926fea04
86 changed files with 10490 additions and 14 deletions
@@ -0,0 +1,44 @@
package connection
import (
"context"
"time"
)
type DialFunc func(context.Context) error
type Reconnector struct {
MaxAttempts int
Delay time.Duration
Dial DialFunc
}
func (r Reconnector) Connect(ctx context.Context) (int, error) {
attempts := r.MaxAttempts
if attempts <= 0 {
attempts = 1
}
var lastErr error
for attempt := 1; attempt <= attempts; attempt++ {
if err := ctx.Err(); err != nil {
return attempt - 1, err
}
if err := r.Dial(ctx); err != nil {
lastErr = err
if attempt < attempts && r.Delay > 0 {
select {
case <-ctx.Done():
return attempt, ctx.Err()
case <-time.After(r.Delay):
}
}
continue
}
return attempt, nil
}
return attempts, lastErr
}