Helper for implementing stateful protocols for EventMachine.