Class TaskUtils
Provides task-related utility functions used by the majority of projects
Inheritance
System.Object
TaskUtils
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Azos
Assembly: Azos.dll
Syntax
public static class TaskUtils
Methods
AsCompletedTask(Action)
Declaration
public static Task AsCompletedTask(this Action act)
Parameters
Type |
Name |
Description |
System.Action |
act |
|
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
AsCompletedTask<T>(Func<T>)
Returns task completed from a synchronous functor
Declaration
public static Task<T> AsCompletedTask<T>(this Func<T> func)
Parameters
Type |
Name |
Description |
System.Func<T> |
func |
|
Returns
Type |
Description |
System.Threading.Tasks.Task<T> |
|
Type Parameters
AssignWorkSegment(Int32, Int32, Int32, out Int32)
Returns the count of items in work segment along with the start index of the first item to be processed
by a particular worker in the worker set
Declaration
public static int AssignWorkSegment(int totalItemCount, int totalWorkerCount, int thisWorkerIndex, out int startIndex)
Parameters
Type |
Name |
Description |
System.Int32 |
totalItemCount |
Total item count in the set processed by all workers
|
System.Int32 |
totalWorkerCount |
Total number of workers int the set operating over the totalItemCount
|
System.Int32 |
thisWorkerIndex |
The index of THIS worker in the whole worker set
|
System.Int32 |
startIndex |
Returns the index of the first item in the assigned segment
|
Returns
Type |
Description |
System.Int32 |
The count of items in the assigned segment
|
OnError(Task, Action)
Registers action executed if task was faulted or cancelled
Declaration
public static Task OnError(this Task task, Action handler)
Parameters
Type |
Name |
Description |
System.Threading.Tasks.Task |
task |
|
System.Action |
handler |
|
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
OnOk(Task, Action, TaskContinuationOptions)
Chains task 'first' with 'next' if first is completed, not cancelled and not faulted.
Returns task that completes when 'next' completes
Declaration
public static Task OnOk(this Task first, Action next, TaskContinuationOptions options = TaskContinuationOptions.ExecuteSynchronously)
Parameters
Type |
Name |
Description |
System.Threading.Tasks.Task |
first |
|
System.Action |
next |
|
System.Threading.Tasks.TaskContinuationOptions |
options |
|
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
OnOk<T1>(Task, Func<Task<T1>>, TaskContinuationOptions, TaskContinuationOptions)
Chains task 'first' with task returned by 'next' if first is completed, not cancelled and not faulted.
Returns task that completes after task returned by 'next' completes with result from 'next' task
Declaration
public static Task<T1> OnOk<T1>(this Task first, Func<Task<T1>> next, TaskContinuationOptions firstOptions = TaskContinuationOptions.ExecuteSynchronously, TaskContinuationOptions nextOptions = TaskContinuationOptions.ExecuteSynchronously)
Parameters
Type |
Name |
Description |
System.Threading.Tasks.Task |
first |
|
System.Func<System.Threading.Tasks.Task<T1>> |
next |
|
System.Threading.Tasks.TaskContinuationOptions |
firstOptions |
|
System.Threading.Tasks.TaskContinuationOptions |
nextOptions |
|
Returns
Type |
Description |
System.Threading.Tasks.Task<T1> |
|
Type Parameters
OnOk<T1>(Task<T1>, Action<T1>, TaskContinuationOptions)
Chains task 'first' with 'next' passing result of 'first' to 'next' if first is completed, not cancelled and not faulted.
Returns task that completes when 'next' completes
Declaration
public static Task OnOk<T1>(this Task<T1> first, Action<T1> next, TaskContinuationOptions options = TaskContinuationOptions.ExecuteSynchronously)
Parameters
Type |
Name |
Description |
System.Threading.Tasks.Task<T1> |
first |
|
System.Action<T1> |
next |
|
System.Threading.Tasks.TaskContinuationOptions |
options |
|
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
Type Parameters
OnOk<T1>(Task<T1>, Func<T1, Task>, TaskContinuationOptions, TaskContinuationOptions)
Chains task 'first' with task returned by 'next' passing result of 'first' to 'next' if first is completed, not cancelled and not faulted.
Returns task that completes after task returned by 'next' completes
Declaration
public static Task OnOk<T1>(this Task<T1> first, Func<T1, Task> next, TaskContinuationOptions firstOptions = TaskContinuationOptions.ExecuteSynchronously, TaskContinuationOptions nextOptions = TaskContinuationOptions.ExecuteSynchronously)
Parameters
Type |
Name |
Description |
System.Threading.Tasks.Task<T1> |
first |
|
System.Func<T1, System.Threading.Tasks.Task> |
next |
|
System.Threading.Tasks.TaskContinuationOptions |
firstOptions |
|
System.Threading.Tasks.TaskContinuationOptions |
nextOptions |
|
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
Type Parameters
OnOk<T1, T2>(Task<T1>, Func<T1, Task<T2>>, TaskContinuationOptions, TaskContinuationOptions)
Chains task 'first' with task returned by 'next' passing result of 'first' to 'next' if first is completed, not cancelled and not faulted.
Returns task that completes after task returned by 'next' completes with result from 'next' task
Declaration
public static Task<T2> OnOk<T1, T2>(this Task<T1> first, Func<T1, Task<T2>> next, TaskContinuationOptions firstOptions = TaskContinuationOptions.ExecuteSynchronously, TaskContinuationOptions nextOptions = TaskContinuationOptions.ExecuteSynchronously)
Parameters
Type |
Name |
Description |
System.Threading.Tasks.Task<T1> |
first |
|
System.Func<T1, System.Threading.Tasks.Task<T2>> |
next |
|
System.Threading.Tasks.TaskContinuationOptions |
firstOptions |
|
System.Threading.Tasks.TaskContinuationOptions |
nextOptions |
|
Returns
Type |
Description |
System.Threading.Tasks.Task<T2> |
|
Type Parameters
OnOkOrError(Task, Action<Task>)
Registers action executed disregarding task state
Declaration
public static Task OnOkOrError(this Task task, Action<Task> handler)
Parameters
Type |
Name |
Description |
System.Threading.Tasks.Task |
task |
|
System.Action<System.Threading.Tasks.Task> |
handler |
|
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
OnOkOrError<T>(Task<T>, Action<Task>)
Registers action executed disregarding task state
Declaration
public static Task<T> OnOkOrError<T>(this Task<T> task, Action<Task> handler)
Parameters
Type |
Name |
Description |
System.Threading.Tasks.Task<T> |
task |
|
System.Action<System.Threading.Tasks.Task> |
handler |
|
Returns
Type |
Description |
System.Threading.Tasks.Task<T> |
|
Type Parameters