Simple evented state machine in NodeJS