Skip to content

Instantly share code, notes, and snippets.

@DamianEdwards
Created July 31, 2013 23:51
Show Gist options
  • Save DamianEdwards/6127298 to your computer and use it in GitHub Desktop.
Save DamianEdwards/6127298 to your computer and use it in GitHub Desktop.
Hub methods with progress support
$.connection.hub.start().done(function() {
var hub = $.connection.myHub;
hub.server.doLongRunningThing()
.progress(function(p) {
console.log("Long running thing: " + p + "%");
})
.done(function() {
console.log("Long running thing complete!");
})
.fail(function(e) {
console.log("Long running thing failed: " + e.message);
});
});
public class MyHub : Hub
{
// The hub method must be Task returning and accept an IProgress<T>
public async Task DoLongRunningThing(IProgress<int> progress)
{
for (var i = 0; i <= 100; i+=5)
{
await Task.Delay(200);
progress.Report(i);
}
}
}
@DamianEdwards
Copy link
Author

@drub0y the progress reporting is 1:1 to the method caller. It's supposed to represent progress of the method duration, so you can't report progress after the method has returned (it throws). This is now implemented in a feature branch (https://github.com/signalr/signalr/tree/feature-2380-hub-progress) if you're interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment