When I issue a SignalR hub method call from the client, I can register to done
and fail
promise-callbacks. However, there is a third, practical one, which is progress
. Can I utilize it somehow to send some kind of intermediate data when the hub operation will take long time? I'd like to keep the done
callback for the real operation result, so I can have a clean client code.
I know I can call whatever client method I want for passing intermediate data, but that's something different, because that's kind of independent from the original server call. I want to have it bound to the server call, you'll understand why.
I have a server operation which runs for minutes, I'd like to pass an ID to the client right after calling it, so the client can cancel it for example.
Here is a scratch.
...
public async Task<LongOperationResult> SomeLongOperation(string someInputData) {
var id = Guid.NewGuid().ToString("N");
// store the id in a static concurrent dictionary, create a cancellation token source, etc.
// send the id here to caller's progress callback somehow
return await Task.Run(() => {
// do the long processing operation
return new LongOperationResult() { ... };
});
}
...
On the client side
hub.server
.someLongOperation(myInput)
.progress(function(id) {
// do something, bind click event of a Cancel button, etc.
})
.done(function(result) {
// do something with result of type LongOperationResult
});
My real scenario is a bit more complex, allowing multiple tasks to run simultaneously, etc. This is just on example of what I'm looking for.