Created
February 4, 2016 13:26
-
-
Save MagnusThor/83803de195c621f9b109 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| using System.Web; | |
| using XSockets.Core.Common.Socket; | |
| using XSockets.Core.Common.Utility.Logging; | |
| using XSockets.Core.XSocket.Helpers; | |
| using XSockets.Plugin.Framework; | |
| namespace MyProject.Helpers | |
| { | |
| public static class MyExtensions | |
| { | |
| public static async Task ChunkInvoke<T,TA>(this T controller, IEnumerable<TA> input,string topic,int size = 10,int wait = 250) where T : class, IXSocketController | |
| { | |
| foreach (var chunk in input.SplitArray(size)) | |
| { | |
| System.Threading.Thread.Sleep(wait); | |
| await controller.Invoke(chunk, topic); | |
| } | |
| } | |
| public static IEnumerable<IEnumerable<T>> SplitArray<T>(this IEnumerable<T> input, int size) | |
| { | |
| var s = input.Select((a, i) => new {Item = a, Index = i}) | |
| .GroupBy(b => (b.Index/size)) | |
| .Select(c => c.Select(d => d.Item)); | |
| return s; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment