[blam] ChannelGroup: don't use Parallel



commit 2e06c67e54b060835c168931bb5bf482f4409fcc
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Sat Jun 15 21:14:07 2013 +0200

    ChannelGroup: don't use Parallel
    
    That waits synchronously for all the threads to return. Use
    Thread.WhenAll() which is awaitable.

 src/ChannelGroup.cs |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)
---
diff --git a/src/ChannelGroup.cs b/src/ChannelGroup.cs
index cafb66e..b6f4486 100644
--- a/src/ChannelGroup.cs
+++ b/src/ChannelGroup.cs
@@ -160,16 +160,11 @@ namespace Imendio.Blam
             return null;
         }
 
-               public delegate bool RefreshDelegate();
-               public bool Refresh()
+               public async Task<bool> RefreshAsync()
                {
-                       Parallel.ForEach(Channels.Cast<Channel>(), c => c.RefreshAsync());
-                       return true; // Whatever
-               }
-
-               public Task<bool> RefreshAsync()
-               {
-                       return Task<bool>.Factory.StartNew(Refresh);
+                       var tasks = Channels.Cast<Channel>().Select(c => c.RefreshAsync());
+                       // FIXME: The continuation is a horrible hack to fit the interface
+                       return await Task.WhenAll(tasks).ContinueWith(task => true);
                }
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]