You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dws/bg/background.go

42 lines
665 B
Go

package bg
import (
8 years ago
"os"
"os/signal"
"github.com/jordanorelli/dws/events"
)
func Run(out chan events.BackgroundEvent, in chan events.UserEvent) {
bg := &background{
in: in,
out: out,
server: newServer(),
}
8 years ago
go bg.handleSignals()
go bg.listen()
bg.run()
}
type background struct {
in chan events.UserEvent
out chan events.BackgroundEvent
*server
}
func (bg *background) run() {
for e := range bg.in {
switch v := e.(type) {
case events.UserSelectedDirectory:
bg.setRoot(v.Path)
}
}
}
8 years ago
func (bg *background) handleSignals() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
bg.out <- events.SigIntEvent{}
}