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
Here is some my own extensions (maybe will be interested to join with Nito's code, like you proj and use it):
public static async ValueTask AsValueTask<T>(this ValueTask<T> valueTask)
=> await valueTask;
public static ValueTask<T> AsValueTask<T>(this Task<T> task)
=> new(task);
public static ValueTask AsValueTask<T>(this Task task)
=> new(task);
public static async ValueTask<T[]> WhenAll<T>(this IEnumerable<ValueTask<T>> tasks)
{
if (tasks is null)
throw new ArgumentNullException(nameof(tasks));
List<Exception> exceptions = null;
var source = tasks.ToArray();
var results = new T[source.Length];
for (var i = 0; i < source.Length; i++)
{
try
{
results[i] = await source[i].ConfigureAwait(false);
}
catch (Exception ex)
{
exceptions ??= new List<Exception>(source.Length);
exceptions.Add(ex);
}
}
if (exceptions is not null)
throw new AggregateException(exceptions);
return results;
}
public static async ValueTask WhenAll(this IEnumerable<ValueTask> tasks)
{
if (tasks is null)
throw new ArgumentNullException(nameof(tasks));
List<Exception> exceptions = null;
var source = tasks.ToArray();
for (var i = 0; i < source.Length; i++)
{
try
{
await source[i].ConfigureAwait(false);
}
catch (Exception ex)
{
exceptions ??= new List<Exception>(source.Length);
exceptions.Add(ex);
}
}
if (exceptions is not null)
throw new AggregateException(exceptions);
}
public static void Run(Func<ValueTask> getTask)
{
if (getTask is null)
throw new ArgumentNullException(nameof(getTask));
AsyncContext.Run(() => getTask().AsTask());
}
public static T Run<T>(Func<ValueTask<T>> getTask)
{
if (getTask is null)
throw new ArgumentNullException(nameof(getTask));
return AsyncContext.Run(() => getTask().AsTask());
}
The text was updated successfully, but these errors were encountered:
Here is some my own extensions (maybe will be interested to join with Nito's code, like you proj and use it):
The text was updated successfully, but these errors were encountered: