1
0
Fork 0

Invert ShouldShutdown logic

This commit is contained in:
Gregory Eremin 2015-10-16 02:27:03 +03:00
parent 06589b9ba2
commit b6f0d2953f
2 changed files with 7 additions and 12 deletions

View File

@ -85,13 +85,13 @@ func (d *BaseDaemon) ShutdownRequested() <-chan struct{} {
return d.shutdown
}
// ShouldShutdown returns true if daemon should shutdown and false otherwise.
func (d *BaseDaemon) ShouldShutdown() bool {
// Continue returns true if daemon should proceed and false if it should stop.
func (d *BaseDaemon) Continue() bool {
select {
case <-d.shutdown:
return true
default:
return false
default:
return true
}
}

View File

@ -19,20 +19,14 @@ func (n *NumberPrinter) Startup() {
log.Println("Oh, crap!")
})
go n.enqueue()
n.SystemProcess(n.enqueue)
}
// Shutdown is empty due to the lack of cleanup.
func (n *NumberPrinter) Shutdown() {}
func (n *NumberPrinter) enqueue() {
for {
select {
case <-n.ShutdownRequested():
return
default:
}
for n.Continue() {
// Generate a random number between 1000 and 9999 and print it
num := 1000 + rand.Intn(9000)
n.Process(n.makeActor(num))
@ -44,6 +38,7 @@ func (n *NumberPrinter) enqueue() {
func (n *NumberPrinter) makeActor(num int) satan.Actor {
return func() {
// Making it crash sometimes
if rand.Intn(20) == 0 {
panic("Noooooooooo!")
}