I've been using boost's asynchronous statechart to write a program. In this program I communicate with another device using an asynchronous serial port. I have a state that waits for a confirmation from the device over the serial port and then posts a "confirmation received" event. This works well but, I would also like to implement a "timeout" event.

In previous programs I had been using switch case statements for my state machines where I had code that could be run each time the loop was run. This meant I could run code and check if I should change state due to something timing out. Like this:

while(1){
    switch (state){
        case 0:{
            sendMessage();
            state = 1;
            sendTime = boost::chrono::steady_clock::now();
        }
        break;
        case 1:{
            if (isConfirmationReceived()){
                // do something
                state = 2;
            }
            else if (boost::chrono::steady_clock::now() > start + boost::chrono::duration<double>(WAIT_LENGTH)){
                //do something
                state = 3;
            }
        }
        break;
        // etc etc

    }
}

How would I implement something like this using boost::StateChart? Or, should i be thinking about this a completely different way?