public async Task CancelTest() { var t0Result = 0; var t0 = new List <int>() { 0 }; var t0Token = new CancellationTokenSource(); var orderTask = Task.Run(() => OrderedParallel.ForEachAsync(t0, async(value, token) => { t0Result += 1; if (token.IsCancellationRequested) { return; } t0Result += 1; await Task.Delay(200); if (token.IsCancellationRequested) { return; } t0Result += 1; }, t0Token.Token, 1)); await Task.Delay(100); t0Token.Cancel(); await orderTask; Assert.AreEqual(2, t0Result); }
public async Task OverThreadCountTest() { var t0 = 0; await OrderedParallel.ForAsync(0, 10, (int index) => t0 += 1, 32); Assert.AreEqual(10, t0); }
public async Task CancelTest() { var t0 = 0; var t0Token = new CancellationTokenSource(); var orderTask = Task.Run(() => OrderedParallel.ForAsync(0, 1, async(index, token) => { t0 += 1; if (token.IsCancellationRequested) { return; } t0 += 1; await Task.Delay(200); if (token.IsCancellationRequested) { return; } t0 += 1; }, t0Token.Token, 1)); await Task.Delay(100); t0Token.Cancel(); await orderTask; Assert.AreEqual(2, t0); }
public async Task ResultTest() { var t0 = new List <int>() { 0, 1, -2, 3, 4, 5, -6, 7, 8, 9 }; var t1 = new List <int>(); var t0Result = 0; var t1Result = 0; await OrderedParallel.ForEachAsync(t0, (value) => t0Result += value); await OrderedParallel.ForEachAsync(t1, (value) => t1Result = 100); Assert.AreEqual(t0.Sum(), t0Result); Assert.AreEqual(0, t1Result); }
public async Task OverThreadCountTest() { var t0 = new List <int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var t0Result = 0; await OrderedParallel.ForEachAsync(t0, (int index) => { t0Result += 1; Console.WriteLine(index); } , 32); Assert.AreEqual(t0.Count, t0Result); }
public async Task ResultTest() { var t0 = 0; var t1 = 0; var t2 = 0; var t3 = 0; await OrderedParallel.ForAsync(0, 0, (int index) => t0 += index); await OrderedParallel.ForAsync(0, -1, (int index) => t1 += index); await OrderedParallel.ForAsync(-1, 1, (int index) => t2 += index); await OrderedParallel.ForAsync(-1, -1, (int index) => t3 += index); Assert.AreEqual(0, t0); Assert.AreEqual(0, t1); Assert.AreEqual(-1, t2); Assert.AreEqual(0, t3); }
public void ParallelerForAsync8() { OrderedParallel .ForAsync(0, 1000, (int i) => { }, 8) .Wait(); }