-
Notifications
You must be signed in to change notification settings - Fork 49
Add support for removing a single subscription handler #592
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
Comments
What about something like this:
And then, no explicit |
yep that sounds good. Since this changes the return type, I think it may not be trivial to deprecate the existing What do you think about offering this through a non-breaking way. One alternative is to have a complete separate function, e.g. // just brainstorming here
Subscriber CreateSubscriber(topic, callback, opts);
Subscriber CreateSubscriptionHandler(topic, callback, opts);
maybe we could do something to forward the args to existing |
Another question, what should be the expected behavior if somebody calls
|
for me, I would expect 2. to happen. The functionality of bool result = node.Subscribe(topic, callback, opts);
Subscriber sub1 = node.CreateSubscriber(topic, callback2, opts);
node.Unsubscribe(topic); // removes both subscriptions and sub1 no longer receives callback bool result = node.Subscribe(topic, callback, opts);
{
Subscriber sub1 = node.CreateSubscriber(topic, callback2, opts);
// sub1 will be unsubscribed once it goes out of scope
}
node.Unsubscribe(topic); // removes remaining (first) subscription
|
Desired behavior
Currently there is one
bool Node::Unsusbcribe(const std::string &_topic)
API which removes all subscription handlers for that topic in the Node. The feature request is to have a variant of theUnsubscribe
API that supports removing just one specific subscription handler from the node.As an example, the current usage of Subscribe / Unsubscribe and their behavior is as shown below:
Ideally we can have something like:
The new APIs above is just for illustrative purposes. It is however a breaking change since it changes the return type from bool to a custom struct / class.
To minimize breaking changes, another option would be to add overloaded
Subscribe(myTopic, callback1, opts, sub1)
API in which you can pass a reference for it to be set by the function.Alternatives considered
See above for alternative API suggestions
Implementation suggestion
For Unsubscribing a single subscription from node, we'll need a function similar to
Node::Unsubscribe
. The difference being:gz-transport/src/Node.cc
Line 615 in 3caed76
gz-transport/src/Node.cc
Line 644 in 3caed76
The text was updated successfully, but these errors were encountered: