Skip to content

Commit

Permalink
Non awaited task in GraphQL DataLoaderExtensions (#11536)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkech authored Apr 15, 2022
1 parent cfa4c0c commit 5ba889e
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GraphQL.DataLoader;

Expand All @@ -19,9 +18,15 @@ public static Task<T[]> LoadAsync<TKey, T>(this IDataLoader<TKey, T> dataLoader,
return Task.WhenAll(tasks);
}

public static Task<T[]> LoadAsync<TKey, T>(this IDataLoader<TKey, T> dataLoader, params TKey[] keys)
public static async Task<T[]> LoadAsync<TKey, T>(this IDataLoader<TKey, T> dataLoader, params TKey[] keys)
{
return dataLoader.LoadAsync(keys.AsEnumerable());
var tasks = new T[keys.Length];
for (var i = 0; i < keys.Length; i++)
{
tasks[i] = await dataLoader.LoadAsync(keys[i]);
}

return tasks;
}
}
}

0 comments on commit 5ba889e

Please sign in to comment.