Title basically says it all. E.g. what if "SendMessage" would return a bool indicating success? Where can I handle the return value?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Meanwhile I managed to figure out that if I have async Task<string> MethodWithReturnValue()
in the Hub I need to use connection.invoke("MethodWithReturnValue").then(function(retval){/*do thing*/});
, but it'd be nice if there would be a code sample for this.
@anurse Should we add this?
@anurse let me know when you have sample code and we'll get this added.
Yes we should add this.
@anurse can you provide a sample that @tdykstra can add?
Same is needed in .NET doc (which also doesn't include specific info about catching exceptions)
JavaScript:
connection.invoke("Add", 40, 2)
.then((result) => alert("40 + 2 = " + result))
.catch((err) => alert("An error occurred: " + err));
.NET:
try
{
result = await connection.InvokeAsync("Add", 40, 2);
}
catch(Exception ex)
{
// Handle exceptions
}
I've been following all the documentation to implement the JavaScript client in one of the solutions I have and I think it is not clear what to do in terms of registration and existing handlers when a disconnection occurs. It's really good the start example but in my opinion it is not enough since I'm not entirely sure what's the best practice here to either reconnect or start a fresh connection by de-registering everything and start all over again. I take from the docs that a simple start would be sufficient?
Thanks,
Carlos.
Filed https://github.com/aspnet/AspNetCore.Docs/pull/12015 for the doc updates.
Most helpful comment
@anurse Should we add this?