A generic API for creating and using state machines.