Beispiel #1
0
        /// <summary>
        /// Performs the given Func parallel for each element in the enumerable.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="T"></typeparam>
        /// <param name="that">The that.</param>
        /// <param name="action">The Func to perform for each element.</param>
        /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
        /// <returns>
        /// IEnumerable of created tasks.
        /// </returns>
        public static IEnumerable <CustomTask <TResult> > ParallelForEach <TResult, T>(this IEnumerable <T> that,
                                                                                       Func <T, TResult> action,
                                                                                       TaskDistributor target)
        {
            var res = that.Select(tmp => CustomTask.Create(() => action(tmp)).Run(target)).CreateList();

            return(res);
        }
Beispiel #2
0
        /// <summary>
        /// Performs the given Func sequential for each element in the enumerable.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="T"></typeparam>
        /// <param name="that">The that.</param>
        /// <param name="action">The Func to perform for each element.</param>
        /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
        /// <returns>
        /// IEnumerable of created tasks.
        /// </returns>
        public static IEnumerable <CustomTask <TResult> > SequentialForEach <TResult, T>(this IEnumerable <T> that,
                                                                                         Func <T, TResult> action, TaskDistributor target)
        {
            var        result   = new List <CustomTask <TResult> >();
            CustomTask lastTask = null;

            foreach (var element in that)
            {
                var tmp  = element;
                var task = CustomTask.Create(() => action(tmp));
                if (lastTask == null)
                {
                    task.Run(target);
                }
                else
                {
                    lastTask.WhenEnded(() => task.Run(target));
                }
                lastTask = task;
                result.Add(task);
            }
            return(result);
        }
Beispiel #3
0
 public DirectoryCopyAction CopyAsync()
 {
     _task = CustomTask.Create <DirectoryCopyAction>(Copy);
     _task.Run();
     return(this);
 }
Beispiel #4
0
 /// <summary>
 ///     Converts the Action into an inactive Task.
 /// </summary>
 /// <returns>The task.</returns>
 public static CustomTask AsTask(this Action that)
 {
     return(CustomTask.Create(that));
 }
Beispiel #5
0
 /// <summary>
 /// Starts the Enumerator as async Task on the given TaskDistributor.
 /// </summary>
 /// <param name="that">The that.</param>
 /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
 /// <returns>
 /// The task.
 /// </returns>
 public static CustomTask RunAsync(this IEnumerator that, TaskDistributor target)
 {
     return(target.Dispatch(CustomTask.Create(that)));
 }
Beispiel #6
0
 /// <summary>
 ///     Starts the given Method as async Task on the given TaskDistributor.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="that">The that.</param>
 /// <param name="methodName">Name of the method.</param>
 /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
 /// <param name="args">Optional arguments passed to the method.</param>
 /// <returns>
 ///     The task.
 /// </returns>
 public static CustomTask <T> RunAsync <T>(this object that, string methodName, TaskDistributor target,
                                           params object[] args)
 {
     return(CustomTask.Create <T>(that, methodName, args).Run(target));
 }