Take your reactor-management code out of your protocol implementation. Replace it with some event-notification code that you can use to learn when the connection has done everything it needs to do. For example, fire a Deferred
.
Then wait on all the deferreds and stop the reactor when they're all done. You might find gatherResults
helpful for this.