【发布时间】:2016-03-17 18:42:10
【问题描述】:
$rootScope.$on('$stateChangeStart', function(event, toState) {
pubnub.unsubscribe({
channel : ["examplechannel1", "examplechannel2"]
});
});
当我导航到另一个页面时,$stateChangeStart 检测到它并运行pubnub.unsubscribe,这是一个同步 XHR 函数(我认为)。根据网络拥塞情况,这会导致 0.5 秒到 3 秒的延迟。如何通过立即更改状态并异步运行取消订阅功能来消除这种延迟?
【问题讨论】:
-
我个人认为您在这里没有提供足够的代码来模拟问题,但我最好的建议是将同步函数转换为 异步 函数,以便您的取消订阅时代码不会停止运行。
标签: angularjs angular-ui-router pubnub