-
Notifications
You must be signed in to change notification settings - Fork 226
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
Multiple handlers for subscriptions #54
Comments
This is my python bias speaking, but There Should On Be One Way To Do It. The first form is more intuitive, and keeps the code shorter (I don't understand why I care about a subscription; that should be an internal object). What I want is the behaviour of jQuery: .subscribe() should append handlers to a list, and you should have an .unsubscribe() which optionally takes the (previously subscribed) function to unsubscribe. My use case is this: I have a stream of numbers coming from my server, and I want to feed them to d3 plots, to a simulated robot on a plot, and to the console for debugging. Maybe the debug prints can sit in one or the other handler, but it would be awkward (and cut across js files) to have both viewing features in one function. If Autobahn doesn't do multiplexing, I'll need the function I pass to .subscribe() be a multiplexer instead of directly being handlers I actually care about. |
Subscriptions are objects since for unsubscribing at the WAMP message level, you need to know the subscription ID - which is stored inside the JS subscription object returned. Not sure if I get you: do you want attaching multiple handlers like this? session.subscribe('com.myapp.topic1', handler1);
session.subscribe('com.myapp.topic1', handler2); If so: this was the API of WAMP v1. Internally, subscriptions would be a dictionary indexed by topic. With WAMP v2 and pattern based subscriptions, this naive view of "topic ~ subscription" no longer holds true. Now, the subscription ID is returned asynchronously from the broker upon subscribing. |
Removing a handler from the list would work as "unwatching": session.subscribe('com.myapp.topic1').then(
function (subscription) {
subscription.watch(handler1);
// stuff
subscription.unwatch(handler1);
}
); Calling For this we need to either use a broker to detect a duplicate subscription and return the existing subscription ID. Or, have a client-side map that uses key material from |
Agree with kousu that I shouldn't have to care where in my code I subscribe to a topic, and how often this happens. My suggestion:
|
Hi, I had many subscription done on same topic name in different angular 2 component.
I need to unsubscribe them.
And this now than troubles come. Any idea ? UPDATE
|
Attaching multiple client-side event handlers to one and the same subscription:
Essentially, the following 2 would be equivalent
and
The difference is: the latter form allows to attach multiple event handlers to one and the same subscription.
The text was updated successfully, but these errors were encountered: