Hub.start - wait for finish

纵饮孤独 提交于 2019-12-11 06:39:39

问题


I'm using SignalR to transferring commands from client to server without refreshing the page. When the client enter some of my web pages, I'm starting a new hub connection. Like this:

var hub = $.connection.siteControllerHub;
$.connection.hub.start();

This "start()" function takes some time (+-5 seconds). mean while, the page is already finished loading and the user start using my UI. SingalR cannot serve the user, until it's finish loading the connection.

I'm know that I'm can use the async approach with the done() register:

$.connection.siteControllerHub.start().done(function () {
    // On finish loading...
});

But this kind of operations is not suitable for me, since if I'm using this - I'm need to disable the UI until this event happens. And this not cool at all.

I'm prefer that loading of the page will takes longer but when it's done, everything will be ready for use.

What do you think? How do you recommend to implement it? Thank you.


回答1:


5 seconds is not normal. Anyway you can queue the messages and when done is called take the queued messages and send to server. Look here for example

https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/blob/master/SignalR.EventAggregatorProxy.Client.JS/jquery.signalR.eventAggregator.js#L173



来源:https://stackoverflow.com/questions/26369495/hub-start-wait-for-finish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!