voryx / angular-wamp

An AngularJS library for AutobahnJS (WAMP v2)
MIT License
133 stars 28 forks source link

Unsubscribe gives error #50

Closed staier closed 8 years ago

staier commented 8 years ago

The code is like this :

oldsubscription= $wamp.subscribe('xxx',func);
.......

$wamp.unsubscribe(oldsubscription);

that gives an error "subscription.unsubscribe is not a function".

$wamp.unsubscribe(oldsubscription.$$state.value) does not give an error. not sure it is correct usage however.

Am i missing something? Please clarify. IMHO it is a bug.

davidwdan commented 8 years ago

@staier oldsubscription returns a promise that resolves with the WAMP Subscription, so you'll need to wait until oldsubscription resolves before you can unsubscribe:

var oldsubscription = $wamp.subscribe('xxxx', func);

oldsubscription.then(function (s) {
        $wamp.unsubscribe(s);
});
staier commented 8 years ago

Thanks for the clarification. However i think this pattern is somewhat too complex. to really unsubscribe i need to create another promise that will call unsubscribe sometime in future, when i do not need it anymore. This is just a thought though.

Another issue is documentation. I believe the issue could be dismissed now. Thanks again.