Last active
August 29, 2015 14:18
-
-
Save vlko/d19875d85e26c4655468 to your computer and use it in GitHub Desktop.
RX.net: Async download with limited concurrency
This file contains 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
private ISubject<string> _downloaderSubject = new Subject<string>(); | |
var processing = _downloaderSubject | |
.Select(url => Observable.FromAsync(x => downloader.GetData(url)) | |
.Catch((Exception ex) => Observable.Throw<JsonData>(ex).DelaySubscription(TimeSpan.FromMilliseconds(1000))) | |
.Retry(3) | |
.Catch<JsonData, Exception>(ex => | |
{ | |
_logger.Error("Failed to download", ex); | |
return Observable.Empty<JsonData>(); | |
})) | |
.Merge(maxConcurrent: 2); | |
processing.Subscribe(x => Console.WriteLine(x),); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment