score:2
Try this:
public static IObservable<List<string>> GetUrlList(Uri url)
{
var result = (
from request in Observable.Return(
GetWebRequest(url, false))
from response in Observable.FromAsyncPattern<WebResponse>(
request.BeginGetResponse, request.EndGetResponse)()
from item in GetUrlCollection(response)
.ToObservable()
.ToArray()
select item
.ToList());
return result;
}
My only concern with this whole approach is that your GetUrlCollection(response)
is returning an enumerable. You really should code this to return an observable.
score:1
Hmmm I think Observable.Start is your friend here. You have a bunch of code that it looks like you are forcing into Observable Sequences, when they really don't look like they are.
Remember Rx is designed to work with sequences of push data. You seem to have a sequence of 1 that happens to be a List. TPL/Task/async would be a good fit here.
If you do want to use Rx, I would suggest avoiding boucing around between IEnumable and IObservable. Doing so is a quick way to creating nasty race conditions and confusing the next developer.
public static IObservable<List<string>> GetUrlList(Uri url)
{
return Observable.Start(()=>
{
var request = GetWebRequest(url, false);
return GetUrlCollection(request);//Code change here??
});
}
Here you can happily be synchronous in your Observable.Start delegate. This should be a lot easier for the next guy to understand (i.e. this is a single value sequence with the UrlCollection as the value).
Source: stackoverflow.com
Related Articles
- Cannot implicitly convert type system linq IQueryable to system collections generic List
- Convert System collection list <anonymous> to generic list<myviewmodel> ASP.NET-MVC5
- List or Array of String Contain specific word in Html Source Code
- How to write a query in order to achieve the orderby descending clause for an uninitialised generic collections such as List of integers in c#?
- c# Linq or code to extract groups from a single list of source data
- How can I sort generic list DESC and ASC?
- Subtract a generic list from another
- Convert DataTable to Generic List in C#
- Find an item in a generic list by specifying multiple conditions
- How to use .Where in generic list
- Simplest way to filter value from generic List in C# using LINQ
- Gridview using a generic list as DataSource and Auto-generating columns
- Converting a XML to Generic List
- Generic List to EntitySet Conversion
- Generic List .First not working LINQ
- Generating the Shortest Regex Dynamically from a source List of Strings
- Visual Studio Code Analysis Rule - "Do not expose generic lists"
- Auto-incrementing a generic list using LINQ in C#
- Remove a property/column from a generic list
- Generic List to CSV String
- C# Generic List Union Question
- Delete an element from a generic list
- Linq OrderBy on generic list returns not entirely alphabetical list
- Sorting a generic list by an external sort order
- How to convert Generic List<anonymous type > to Generic List <Classname>?
- Execute method for each object in generic list using lambda
- LINQ Source Code Available
- Checking for item in Generic List before using it
- Removing Duplicates from bottom of Generic List
- .NET 4 Code Contracts: "requires unproven: source != null"
- LINQ deferred execution - why is it not considering the change from the result of Enumerable.Range?
- LINQ using Contains with entity
- Entity framework insert update problem!
- Selecting columns in DataLoadOptions
- using Linq with multiple where conditions
- How get unmatched list from dictionary
- Create JSON arrays using LINQ
- Using external list to order a linq query
- Grouped custom object with a list property
- how to build Expression<Func<x,y>> with no input parameters?
- Web Api 2 - converting values and combine values from sub query
- Convert or map a class instance to a list of another one by using Lambda or LINQ?
- Can a linq query using join do the select part using a lambda function with no extension methods?
- c# and mongodb: Aggregates with filter
- c# XML to linq error if null
- Return 2 properties from a list using lambda ID(distinct) and the count of the specific ID?
- List<T> All rows update
- Why can't I select data from my LINQ sub query join?
- How to make my linq to entities query for sum faster
- Why does my query fail to load related data in EF?