comparison Implab/Parallels/ArrayTraits.cs @ 101:279e226dffdd v2

code cleanup added EnsureDispatched extension
author cin
date Thu, 06 Nov 2014 20:03:19 +0300
parents 4c0e5ef99986
children 5f10d54b45df
comparison
equal deleted inserted replaced
100:673947ce458a 101:279e226dffdd
1 using Implab.Diagnostics; 1 using Implab.Diagnostics;
2 using System; 2 using System;
3 using System.Collections.Generic;
4 using System.Diagnostics; 3 using System.Diagnostics;
5 using System.Linq;
6 using System.Text;
7 using System.Threading; 4 using System.Threading;
8 5
9 namespace Implab.Parallels { 6 namespace Implab.Parallels {
10 public static class ArrayTraits { 7 public static class ArrayTraits {
11 class ArrayIterator<TSrc> : DispatchPool<int> { 8 class ArrayIterator<TSrc> : DispatchPool<int> {
144 141
145 var iter = new ArrayIterator<TSrc>(source, action, threads); 142 var iter = new ArrayIterator<TSrc>(source, action, threads);
146 return iter.Promise; 143 return iter.Promise;
147 } 144 }
148 145
149 public static IPromise<TDst[]> ChainedMap<TSrc, TDst>(this TSrc[] source, ResultMapper<TSrc, IPromise<TDst>> transform, int threads) { 146 public static IPromise<TDst[]> ChainedMap<TSrc, TDst>(this TSrc[] source, Func<TSrc, IPromise<TDst>> transform, int threads) {
150 if (source == null) 147 if (source == null)
151 throw new ArgumentNullException("source"); 148 throw new ArgumentNullException("source");
152 if (transform == null) 149 if (transform == null)
153 throw new ArgumentNullException("transform"); 150 throw new ArgumentNullException("transform");
154 if (threads <= 0) 151 if (threads <= 0)
155 throw new ArgumentOutOfRangeException("Threads number must be greater then zero"); 152 throw new ArgumentOutOfRangeException("threads","Threads number must be greater then zero");
156 153
157 if (source.Length == 0) 154 if (source.Length == 0)
158 return Promise<TDst[]>.ResultToPromise(new TDst[0]); 155 return Promise<TDst[]>.ResultToPromise(new TDst[0]);
159 156
160 var promise = new Promise<TDst[]>(); 157 var promise = new Promise<TDst[]>();