0
$rootScope.$on('$stateChangeStart', function(event, toState) {
    pubnub.unsubscribe({
        channel : ["examplechannel1", "examplechannel2"]
    });
});

When I navigate to another page, $stateChangeStart detects it and runs pubnub.unsubscribe, a synchronous XHR function (I think). This causes a delay of anywhere from 0.5s to 3s depending on network congestion. How can I eliminate this delay by changing the state immediately and running the unsubscribe function asynchronously?

jcharch
  • 150
  • 16
  • I personally think you aren't providing enough code here to simulate the issue, but my best piece of advice would be to turn that synchronous function to an **asynchronous** one so your code doesn't stop running while its unsubscribing. – realappie Mar 17 '16 at 18:44

1 Answers1

1

I always ask too soon before exhausting the Google resource

Answer: https://www.pubnub.com/community/discussion/660/missing-pubnub-message-with-angular-js Set noleave to true in Pubnub init function

jcharch
  • 150
  • 16