mirror of
https://github.com/kemko/reproxy.git
synced 2026-01-01 15:55:49 +03:00
* wip * resolve merge artifacts * full coverage for conductor * wire plugin conductor to main and proxy * wip, with separate match handler * split matching logic with another handler, add initial docs * move parts of proxy to handlers, add tests * add headers in to be sent to proxied url * merged from master * add example with docker compose * supress excesive debug reporting 0-9 disabled in docker * add plugin tests * randomize test port * lint: minor warns * lint: err shadow
37 lines
688 B
Go
37 lines
688 B
Go
package strategy
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// FixedDelay implements strategy.Interface for fixed intervals up to max repeats
|
|
type FixedDelay struct {
|
|
Repeats int
|
|
Delay time.Duration
|
|
}
|
|
|
|
// Start returns channel, similar to time.Timer
|
|
// then publishing signals to channel ch for retries attempt.
|
|
// can be terminated (canceled) via context.
|
|
func (s *FixedDelay) Start(ctx context.Context) <-chan struct{} {
|
|
if s.Repeats == 0 {
|
|
s.Repeats = 1
|
|
}
|
|
ch := make(chan struct{})
|
|
go func() {
|
|
defer func() {
|
|
close(ch)
|
|
}()
|
|
for i := 0; i < s.Repeats; i++ {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case ch <- struct{}{}:
|
|
}
|
|
sleep(ctx, s.Delay)
|
|
}
|
|
}()
|
|
return ch
|
|
}
|