Skip to content

Instantly share code, notes, and snippets.

@geektoni
Last active June 14, 2017 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geektoni/73fa6ce5bd73ffb497081041b72af102 to your computer and use it in GitHub Desktop.
Save geektoni/73fa6ce5bd73ffb497081041b72af102 to your computer and use it in GitHub Desktop.
init_shogun(bool active=true) {
Some<CSignal> sg_signal = some<CSignal>(active);
std::signal(SIGINT, sg_signal.handler());
std::signal(SIGURG, sg_signal.handler());
}
CSignal {
public:
CSignal(bool active) : m_active(active)
{
// Premature stopping
sigint_observable = observable<>::create<int>(
[](subscriber<int> s){
s.on_completed();
}
).publish();
// Skip on next
sigurg_observable = observable<>::create<int>(
[](subscriber<int> s){
s.on_next(1);
}
).publish();
}
void handler(int signal)
{
if (!active)
return;
switch(signal)
case SIGINT:
sg_signal.connect();
...
}
bool m_active;
observer m_sigint_obs;
observer m_sigurg_obs;
static sg_signal = m_sigint_obs+m_sigurg_obs;
}
SGObject() {
protected:
virtual void on_next();
virtual void on_completed();
private:
void register() {
sg_signal.subscribe(rxcpp::make_subscriber<int>(
rxcpp::composite_subscription(), on_next, on_complete
);
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment