【问题标题】:On $stateChangeStart detect, change state immediately and run function in parallel在 $stateChangeStart 检测时,立即更改状态并并行运行函数
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多