
On 3 July 2015 at 13:16, Andrew Barnert <abarnert@yahoo.com> wrote:
The difference between a server and an MDI app is that you usually need hundreds or thousands of connections as opposed to a handful of documents, but the control flow for each is usually more linear, so the wizard-like design is a much more obvious choice.
Ah, thank you - yes, the "stepping through a wizard" case is a good example, as it hits the same kind multi-step process that causes problems with network applications. Simple request-response cases are easy to handle with callbacks: "event A happens, invoke callback B, which will trigger action C". If things stop there, you're fine. Things get messier when they start looking like this: "event A happens, invoking callback B, which triggers action C after setting up callback D to wait for event E, which triggers action F after setting up callback G to wait for event H and finally trigger action I" This is where coroutines help, as that second case instead becomes: "event A happens, invoking coroutine B, which triggers action C, then waits for event E, then triggers action F, then waits for event H, then triggers the final action I" Rather than having to create a new callback to handle each new action-event pair, you can instead have a single coroutine which triggers an action, and then waits for the corresponding event, and may do this multiple times before terminating. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia