Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an overload for ToAsyncEnumerable that takes a custom TaskScheduler #297

Closed
yariker opened this issue Nov 18, 2016 · 6 comments
Closed

Comments

@yariker
Copy link

yariker commented Nov 18, 2016

Current implementation of AsyncEnumerable.ToAsyncEnumerable<TSource>(this IEnumerable<TSource> source) does not allow you to pass a custom TaskScheduler, thus, it provides no control on how the tasks are scheduled.

It would be nice to have an overload that takes a TaskScheduler (or maybe even a TaskFactory<bool>) as a parameter.

@shiftkey
Copy link
Contributor

@krs500 can you give an example of how this is hard to control/test? For the most part we're using Task.FromResult (at least in 3.1) so I'd love to understand more about the problems you're facing and see what the net effect of this overload will be...

@yariker
Copy link
Author

yariker commented Nov 18, 2016

I just realized that in v3.1.0, the ToAsyncEnumerable behaves in a very different way than in v3.0.0. And I am stuck to v3.0.0, because v3.1.0 targets .NET Standard instead of the full .NET Framework (see #295).

In v3.0.0, it uses Task.Factory.StartNew to invoke IEnumerator.MoveNext asynchronously. In v3.1.0, the IEnumerator.MoveNext is invoked synchronously, in a blocking way. This negates all the benefits of IAsyncEnumerable, but that's a different question...

You're right that it makes no sense to use schedulers for Task.FromResult, since it returns a task that is already completed.

In my scenario, I use a custom task scheduler that queues the tasks to run on a specific "working" thread, instead of the .NET thread pool (which is a default behavior of Task.Factory.StartNew when you don't specify a scheduler). Others might want to use a custom scheduler, for example, to target a specific SynchronizationContext, to limit the concurrency level, to target the the I/O thread pool, etc.

@shiftkey
Copy link
Contributor

cc @onovotny for feels on ☝️

@clairernovotny
Copy link
Member

@krs500 I responded here...
#295 (comment) Does that help?

@yariker
Copy link
Author

yariker commented Nov 19, 2016

Although NETStandard.Library is fully supported for net45, as you say, I can't afford shipping the whole NETStandard.Library along with my desktop app, especially when it is just a subset of the full .NET, from the API perspective. Why I can't reuse the .NET Framework that is already installed? But this is not the question that I'm asking.

As for the questions posted above, no, that doesn't help.

@clairernovotny
Copy link
Member

clairernovotny commented Mar 2, 2019

Closing due to age. Please open a new issue based on the 4.0 preview behavior and functionality if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants