refresh users global ch
parent
2113252e2d
commit
97cc3ae151
|
|
@ -6,6 +6,15 @@ import (
|
|||
"mayhem-party/src/device/input/button"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
ChanSigUsr1 = func() chan os.Signal {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGUSR1)
|
||||
return c
|
||||
}()
|
||||
)
|
||||
|
||||
type Refresh struct {
|
||||
|
|
@ -13,13 +22,11 @@ type Refresh struct {
|
|||
input Wrap
|
||||
}
|
||||
|
||||
func NewRefreshCh(sig os.Signal) <-chan os.Signal {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, sig)
|
||||
return c
|
||||
func NewRefresh(newWrap func() Wrap) *Refresh {
|
||||
return NewRefreshWith(newWrap, ChanSigUsr1)
|
||||
}
|
||||
|
||||
func NewRefresh(newWrap func() Wrap, ch <-chan os.Signal) *Refresh {
|
||||
func NewRefreshWith(newWrap func() Wrap, ch <-chan os.Signal) *Refresh {
|
||||
ctx, can := context.WithCancel(context.Background())
|
||||
result := &Refresh{
|
||||
can: can,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ func TestRefresh(t *testing.T) {
|
|||
}
|
||||
ch := make(chan os.Signal, 1)
|
||||
defer close(ch)
|
||||
refresh := NewRefresh(generator, ch)
|
||||
refresh := NewRefreshWith(generator, ch)
|
||||
defer refresh.Close()
|
||||
|
||||
assertIts := func(t *testing.T, b byte) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,12 @@ import (
|
|||
"context"
|
||||
"mayhem-party/src/device/input/button"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
FlagBuffered = os.Getenv("WRAP_BUFFERED") == "true"
|
||||
FlagRemapFile = os.Getenv("WRAP_REMAP_FILE")
|
||||
FlagRefreshOnSigUsr1 = os.Getenv("WRAP_REFRESH_ON_SIGUSR1") == "true"
|
||||
)
|
||||
|
||||
type Wrap interface {
|
||||
|
|
@ -16,23 +21,22 @@ func New(ctx context.Context, srcFunc func() button.Parser) Wrap {
|
|||
maker := func() Wrap {
|
||||
return srcFunc()
|
||||
}
|
||||
if os.Getenv("WRAP_BUFFERED") == "true" {
|
||||
if FlagBuffered {
|
||||
oldMaker := maker
|
||||
maker = func() Wrap {
|
||||
return NewBuffered(ctx, oldMaker())
|
||||
}
|
||||
}
|
||||
if p := os.Getenv("WRAP_REMAP_FILE"); p != "" {
|
||||
if FlagRemapFile != "" {
|
||||
oldMaker := maker
|
||||
maker = func() Wrap {
|
||||
return NewRemapFromFile(oldMaker(), p)
|
||||
return NewRemapFromFile(oldMaker(), FlagRemapFile)
|
||||
}
|
||||
}
|
||||
if os.Getenv("WRAP_REFRESH_ON_SIGUSR1") != "" {
|
||||
if FlagRefreshOnSigUsr1 {
|
||||
oldMaker := maker
|
||||
c := NewRefreshCh(syscall.SIGUSR1)
|
||||
maker = func() Wrap {
|
||||
return NewRefresh(oldMaker, c)
|
||||
return NewRefresh(oldMaker)
|
||||
}
|
||||
}
|
||||
return maker()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package wrap_test
|
||||
|
||||
import (
|
||||
"mayhem-party/src/device/input/wrap"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewRefreshing(t *testing.T) {
|
||||
wrap.FlagBuffered = true
|
||||
}
|
||||
Loading…
Reference in New Issue