Operating on state indexes is very widespread in the codebase now and having checking methods directly on the Time struct makes asserting prev/next state in transition handlers short and concise.
Example from rpc#Client:
func (c *Client) StartEnd(e *am.Event) {
// gather state from before the transition
before := e.Transition().TimeBefore
mach := e.Machine
wasConn := before.Is1(mach.Index(ss.Connecting)) ||
before.Is1(mach.Index(ss.Connected))
// graceful disconnect
if wasConn {
c.Mach.Add1(ss.Disconnecting, nil)
}
}
Operating on state indexes is very widespread in the codebase now and having checking methods directly on the
Time
struct makes asserting prev/next state in transition handlers short and concise.Example from
rpc#Client
:Theres helpers for lists of indexes.