theraot / Theraot

Backporting .NET and more: LINQ expressions in .net 2.0 - nuget Theraot.Core available.
MIT License
158 stars 30 forks source link

TaskExEx #131

Closed NN--- closed 3 years ago

NN--- commented 3 years ago

Is it by design ?

public static partial class TaskExEx

Why there is TaskEx.FromResult https://github.com/theraot/Theraot/blob/master/Framework.Core/System/Threading/Tasks/TaskEx.cs But there is no TaskEx.FromCancelled.

theraot commented 3 years ago

Because TaskEx is from the Async CTP, and it does not have FromCanceled in Microsoft version.

See: https://github.com/microsoft/referencesource/blob/master/Microsoft.Bcl.Async/Microsoft.Threading.Tasks/Threading/Tasks/TaskEx.cs

Now that you mention it, I should review the targets where you can have TaskEx from Microsoft.

I guess I can extend TaskEx to include FromResult.

Regardless TaskExEx is there for those platforms where you can get both Taks and TaskEx from Microsoft (and we don't want to conflict with Microsoft), and FromResult is missing in that case, so you get it from TaskExEx.

Notice TaskExEx does not have conditional compilation, it is always there.

NN--- commented 3 years ago

Ok. As usual MS make everything more complicated :)

NN--- commented 3 years ago

Currently due to lack of FromResult in TaskEx I have two conditionals, for TaskEx and for TaskExEx instead of having only one.

theraot commented 3 years ago

You should be able to get both FromCanceled and FromResult from TaskExEx always,

https://github.com/theraot/Theraot/blob/master/Framework.Core/System/Threading/Tasks/TaskExEx.fromcanceled.cs https://github.com/theraot/Theraot/blob/master/Framework.Core/System/Threading/Tasks/TaskExEx.fromresult.cs

If that does not work, then I need to fix that.

NN--- commented 3 years ago

I understand, what I do is the following to make usage of types from CLR as much as possible.

#if NET45_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP
using TaskEx = System.Threading.Tasks.Task;
#else
using TaskEx = System.Threading.Tasks.TaskEx;
#endif

#if NET46_OR_GREATER || NETSTANDARD13_OR_GREATER || TARGETS_NETCOREAPP
using TaskExEx = System.Threading.Tasks.Task;
#else
using TaskExEx = System.Threading.Tasks.TaskExEx;
#endif
theraot commented 3 years ago

I see,

I guess these tend to accumulate.

That makes me wish you could do it in a single place. Some sort of global type alias or typedef. TypeForwardedToAttribute comes to mind, but, it is not the same thing.

NN--- commented 3 years ago

One day there will global type alias.