Last active
June 14, 2017 13:37
-
-
Save geektoni/73fa6ce5bd73ffb497081041b72af102 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
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