summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Util.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-02-09 15:31:56 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2013-02-09 15:31:56 -0800
commit794a08cc9a84f4a1b6ec233e7733704de1fc04cb (patch)
tree91a9dcb2c3aa90560330f860b23e733c46cdfa29 /src/DotNetOpenAuth.Core/Util.cs
parent2e177b1c58ccd1c8edc2cc78e0c629784173a95c (diff)
downloadDotNetOpenAuth-794a08cc9a84f4a1b6ec233e7733704de1fc04cb.zip
DotNetOpenAuth-794a08cc9a84f4a1b6ec233e7733704de1fc04cb.tar.gz
DotNetOpenAuth-794a08cc9a84f4a1b6ec233e7733704de1fc04cb.tar.bz2
Assocations with providers when OpenID discovery yields multiple endpoints can now happen in parallel.
Diffstat (limited to 'src/DotNetOpenAuth.Core/Util.cs')
-rw-r--r--src/DotNetOpenAuth.Core/Util.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Core/Util.cs b/src/DotNetOpenAuth.Core/Util.cs
index d4204a0..a23b4d8 100644
--- a/src/DotNetOpenAuth.Core/Util.cs
+++ b/src/DotNetOpenAuth.Core/Util.cs
@@ -7,10 +7,12 @@ namespace DotNetOpenAuth {
using System;
using System.Collections.Generic;
using System.Globalization;
+ using System.Linq;
using System.Net;
using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
+ using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using DotNetOpenAuth.Configuration;
@@ -226,6 +228,22 @@ namespace DotNetOpenAuth {
}
/// <summary>
+ /// Creates a dictionary of a sequence of elements and the result of an asynchronous transform,
+ /// allowing the async work to proceed concurrently.
+ /// </summary>
+ /// <typeparam name="TSource">The type of the source.</typeparam>
+ /// <typeparam name="TResult">The type of the result.</typeparam>
+ /// <param name="source">The source.</param>
+ /// <param name="transform">The transform.</param>
+ /// <returns></returns>
+ internal static async Task<Dictionary<TSource, TResult>> ToDictionaryAsync<TSource, TResult>(
+ this IEnumerable<TSource> source, Func<TSource, Task<TResult>> transform) {
+ var taskResults = source.ToDictionary(s => s, transform);
+ await Task.WhenAll(taskResults.Values);
+ return taskResults.ToDictionary(p => p.Key, p => p.Value.Result);
+ }
+
+ /// <summary>
/// Manages an individual deferred ToString call.
/// </summary>
/// <typeparam name="T">The type of object to be serialized as a string.</typeparam>