Nat Goodspeed: Using Boost.Coroutine to untangle a state machine
У вашего броузера проблема в совместимости с HTML5
NAt's talk from C++Now! 2012
This is a case study of startup in an event-driven program. The program makes a sequence of requests to external servers, waiting for each result before making the next such request.
Originally this was coded as a Big Switch Statement with a global int state variable. The containing function was called every frame, jumping to the current state logic, modifying the state variable on arrival of that state's result.
A colleague reimplemented this using Boost.Statechart, expressing the logic as a collection of classes.
In neither case was the structure of the logic apparent. Discovering the actual control flow required careful study of all components.
We reimplemented the same logic as a coroutine, in which each request to an external server is expressed as a function call that waits for results to arrive. Calling such a function blocks only the coroutine; normal per-frame processing proceeds on the main stack. This exposes the actual startup control flow as a triply-nested loop, readily visible to anyone familiar with C++. Moreover, maintenance (e.g. inserting a new request) is entirely straightforward — which cannot be said of the previous implementations.