Last active
December 29, 2016 09:38
-
-
Save LuxoftAKutsan/16fc3d16a0d2ca91d9be9689236ea56f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <M> | |
class AsyncMessageProcessor { | |
Handle() = 0; | |
ProcessMessage(M m ) { | |
// put message in queue | |
} | |
Thread tread; // thread pop messages from queue and call Handle for each | |
void Stop() { | |
// forbid push | |
// clear queue ( optional) | |
thread.join() // process left messages | |
} | |
virtual ~AsyncMessageProcessor() {} | |
}; | |
class XMessagePtocessor : public AsyncMessageProcessor<XMessage> { | |
void Handle(XMessage m) override { | |
// do staff | |
} | |
~XMessagePtocessor() { | |
Stop(); // I would like to avoid explicitely call Stop in ~XMessagePtocessor | |
} | |
}; | |
// Preferable usage : | |
{ | |
XMessagePtocessor p; | |
for (XMessage m: messages) { | |
p.ProcessMessage(m) | |
} | |
} // there code should safely destroy XMessagePtocessor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment