Invert ShouldShutdown logic
This commit is contained in:
parent
06589b9ba2
commit
b6f0d2953f
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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!")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue