You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is the sourcing of the stream thread safe? I.e. would the below situation cause any issues I'm unaware of. I have a situation where I need to make a large amount of async requests that generate the async stream, and want to do the sourcing requests in parallel (unordered), and then push into the async stream. Will that create any negative side effects I'm not seeing?
[Fact]
public void TestAsyncStreams()
{
IList<string> urls = new List<string>() {
"http://www.google.com",
"http://www.microsoft.com",
"http://www.github.com"
};
var result = new ConcurrentBag<string>();
var asyncEnumerableCollection = ProduceWebPages(urls, CancellationToken.None);
asyncEnumerableCollection.ForEachAsync(async page => {
result.Add(page);
}).Wait();
Assert.Equal(urls.Count, result.Count);
}
static IAsyncEnumerable<string> ProduceWebPages(IEnumerable<string> urls, CancellationToken cancellationToken)
{
return new AsyncEnumerable<string>(async yield => {
await urls.ParallelForEachAsync(
async uri =>
{
using (var client = new HttpClient())
{
var str = await client.GetStringAsync(uri);
await yield.ReturnAsync(str);
}
},
maxDegreeOfParalellism: 5,
cancellationToken: cancellationToken);
Console.WriteLine("Done");
});
}
The text was updated successfully, but these errors were encountered:
Is the sourcing of the stream thread safe? I.e. would the below situation cause any issues I'm unaware of. I have a situation where I need to make a large amount of async requests that generate the async stream, and want to do the sourcing requests in parallel (unordered), and then push into the async stream. Will that create any negative side effects I'm not seeing?
The text was updated successfully, but these errors were encountered: