在 $stateChangeStart 检测上,立即更改状态并并行执行 运行 函数

On $stateChangeStart detect, change state immediately and run function in parallel

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

当我导航到另一个页面时,$stateChangeStart 检测到它并运行 pubnub.unsubscribe,一个同步 XHR 函数(我认为)。这会导致延迟从 0.5 秒到 3 秒不等,具体取决于网络拥塞情况。如何通过立即更改状态和 运行 异步取消订阅功能来消除这种延迟?

我总是在用完 Google 资源之前问得太早

答案:https://www.pubnub.com/community/discussion/660/missing-pubnub-message-with-angular-js 在 Pubnub init 函数中将 noleave 设置为 true