Skip to content

Instantly share code, notes, and snippets.

@vlko
Last active August 29, 2015 14:18
Show Gist options
  • Save vlko/d19875d85e26c4655468 to your computer and use it in GitHub Desktop.
Save vlko/d19875d85e26c4655468 to your computer and use it in GitHub Desktop.
RX.net: Async download with limited concurrency
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