Files
reproxy/examples/plugin/vendor/github.com/go-pkgz/repeater/strategy/strategy.go
Umputun 7139c57766 RPC plugins support (#85)
* 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
2021-06-01 02:56:39 -05:00

36 lines
774 B
Go

// Package strategy defines repeater's strategy and implements some.
// Strategy result is a channel acting like time.Timer ot time.Tick
package strategy
import (
"context"
"time"
)
// Interface for repeater strategy. Returns channel with ticks
type Interface interface {
Start(ctx context.Context) <-chan struct{}
}
// Once strategy eliminate repeats and makes a single try only
type Once struct{}
// Start returns closed channel with a single element to prevent any repeats
func (s *Once) Start(ctx context.Context) <-chan struct{} {
ch := make(chan struct{})
go func() {
ch <- struct{}{}
close(ch)
}()
return ch
}
func sleep(ctx context.Context, duration time.Duration) {
select {
case <-time.After(duration):
return
case <-ctx.Done():
return
}
}