Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to determine whether a signal has listeners #995

Merged
merged 2 commits into from Sep 16, 2016

Conversation

codemercenary
Copy link
Contributor

Some signals are actually quite expensive to assert. It would be helpful to be able to query a signal to determine whether it has listeners before doing work to try to invoke it.

Some signals are actually quite expensive to assert.  It would be helpful to be able to query a signal to determine whether it has listeners before doing work to try to invoke it.
autowiring::signal<void()> s;
ASSERT_FALSE(s) << "Signal did not correctly report it had no listeners";
s += [] {};
ASSERT_TRUE(s) << "Signal stated that it had no listeners when it should have had at least one";
Copy link
Contributor

@yuwilbur yuwilbur Sep 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can add one more additional use case such that:

auto listener = [] {};
auto registration = s += listener;
ASSERT_TRUE(s) << "Signal stated that it had no listeners when it should have had at least one";
s -= resgistration;
ASSERT_FALSE(s) << "Signal stated that it has listeners after removing all listeners";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@yuwilbur
Copy link
Contributor

Looks good!

@yuwilbur yuwilbur merged commit 6155307 into master Sep 16, 2016
@yuwilbur yuwilbur deleted the feature-signalhandlerquery branch September 16, 2016 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants