Skip to content

Instantly share code, notes, and snippets.

@MagnusThor
Created February 4, 2016 13:26
Show Gist options
  • Select an option

  • Save MagnusThor/83803de195c621f9b109 to your computer and use it in GitHub Desktop.

Select an option

Save MagnusThor/83803de195c621f9b109 to your computer and use it in GitHub Desktop.
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