diff options
| author | Ryan Dahl <ry@tinyclouds.org> | 2018-05-25 15:36:13 -0400 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-05-25 16:16:28 -0400 |
| commit | 0fe6ab91df7158cacd5c2a632d36066251a292c4 (patch) | |
| tree | 054673ba8b49ce6a122cf02612a80ecb5c89f0aa /timers.go | |
| parent | 5b858632acb672c1f38145edac9df11fdbcacad6 (diff) | |
Finish de-oneof-ing
Diffstat (limited to 'timers.go')
| -rw-r--r-- | timers.go | 33 |
1 files changed, 15 insertions, 18 deletions
@@ -19,27 +19,27 @@ func InitTimers() { Sub("timers", func(buf []byte) []byte { msg := &Msg{} check(proto.Unmarshal(buf, msg)) - switch msg.Payload.(type) { - case *Msg_TimerStart: - payload := msg.GetTimerStart() - timers[payload.Id] = &Timer{ - Id: payload.Id, + switch msg.Command { + case Msg_TIMER_START: + id := msg.TimerStartId + t := &Timer{ + Id: id, Done: false, - Interval: payload.Interval, - Duration: payload.Duration, + Interval: msg.TimerStartInterval, + Duration: msg.TimerStartDuration, Cleared: false, } - timers[payload.Id].StartTimer() + t.StartTimer() + timers[id] = t return nil - case *Msg_TimerClear: - payload := msg.GetTimerClear() + case Msg_TIMER_CLEAR: // TODO maybe need mutex here. - timer := timers[payload.Id] + timer := timers[msg.TimerClearId] timer.Clear() - return nil default: panic("[timers] Unexpected message " + string(buf)) } + return nil }) } @@ -62,12 +62,9 @@ func (t *Timer) StartTimer() { t.Done = true } PubMsg("timers", &Msg{ - Payload: &Msg_TimerReady{ - TimerReady: &TimerReadyMsg{ - Id: t.Id, - Done: t.Done, - }, - }, + Command: Msg_TIMER_READY, + TimerReadyId: t.Id, + TimerReadyDone: t.Done, }) if t.Done { return |
