SignalR function return value

No1Lives4Ever picture No1Lives4Ever · Oct 27, 2014 · Viewed 8.7k times · Source

I created a SignalR hub which contain the following hub function:

public bool GetStatus()
{
    return true;
}

I'm want to call this function from my JS code and get the request of this call. Something like this:

var result = hub.server.getStatus();
if (result)
    alert('success');

Is this possible without returning Task of bool?

Thank you.

Answer

wgraham picture wgraham · Oct 27, 2014

No. The SignalR JavaScript client is non-blocking; you will need to follow the Promise interface, like so:

hub.server.getStatus().done(function(result) { 
    if (result) {
        alert('success'); 
    }
});