Created
July 31, 2013 23:51
-
-
Save DamianEdwards/6127298 to your computer and use it in GitHub Desktop.
Hub methods with progress support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.