Table of Contents

Class AsyncPatterns

Namespace
Cuemon.Threading
Assembly
Cuemon.Threading.dll

Provides a generic way to support different types of design patterns and practices with small utility methods scoped to Task.

public sealed class AsyncPatterns
Inheritance
AsyncPatterns

Properties

Use

Gets the singleton instance of the AsyncPatterns functionality allowing for extensions methods like: AsyncPatterns.Use.SomeIngeniousMethod().

public static AsyncPatterns Use { get; }

Property Value

AsyncPatterns

The singleton instance of the AsyncPatterns functionality.

Methods

SafeInvokeAsync<TResult>(Func<TResult>, Func<TResult, CancellationToken, Task<TResult>>, Func<Exception, CancellationToken, Task>, CancellationToken)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

public static Task<TResult> SafeInvokeAsync<TResult>(Func<TResult> initializer, Func<TResult, CancellationToken, Task<TResult>> tester, Func<Exception, CancellationToken, Task> catcher = null, CancellationToken ct = default(CancellationToken))
    where TResult : class, IDisposable

Parameters

initializer Func<TResult>

The function delegate that initializes an object implementing the IDisposable interface.

tester Func<TResult, CancellationToken, Task<TResult>>

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

catcher Func<Exception, CancellationToken, Task>

The function delegate that will handle any exceptions that might have been thrown by tester.

ct CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters

TResult

The type of the return value of the function delegate initializer.

SafeInvokeAsync<T, TResult>(Func<TResult>, Func<TResult, T, CancellationToken, Task<TResult>>, T, Func<Exception, T, CancellationToken, Task>, CancellationToken)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

public static Task<TResult> SafeInvokeAsync<T, TResult>(Func<TResult> initializer, Func<TResult, T, CancellationToken, Task<TResult>> tester, T arg, Func<Exception, T, CancellationToken, Task> catcher = null, CancellationToken ct = default(CancellationToken))
    where TResult : class, IDisposable

Parameters

initializer Func<TResult>

The function delegate that initializes an object implementing the IDisposable interface.

tester Func<TResult, T, CancellationToken, Task<TResult>>

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

arg T

The parameter of the function delegate tester and delegate catcher.

catcher Func<Exception, T, CancellationToken, Task>

The function delegate that will handle any exceptions that might have been thrown by tester.

ct CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters

T

The type of the parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

SafeInvokeAsync<T1, T2, TResult>(Func<TResult>, Func<TResult, T1, T2, CancellationToken, Task<TResult>>, T1, T2, Func<Exception, T1, T2, CancellationToken, Task>, CancellationToken)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

public static Task<TResult> SafeInvokeAsync<T1, T2, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, Func<Exception, T1, T2, CancellationToken, Task> catcher = null, CancellationToken ct = default(CancellationToken))
    where TResult : class, IDisposable

Parameters

initializer Func<TResult>

The function delegate that initializes an object implementing the IDisposable interface.

tester Func<TResult, T1, T2, CancellationToken, Task<TResult>>

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

arg1 T1

The first parameter of the function delegate tester and delegate catcher.

arg2 T2

The second parameter of the function delegate tester and delegate catcher.

catcher Func<Exception, T1, T2, CancellationToken, Task>

The function delegate that will handle any exceptions that might have been thrown by tester.

ct CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters

T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

SafeInvokeAsync<T1, T2, T3, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, CancellationToken, Task<TResult>>, T1, T2, T3, Func<Exception, T1, T2, T3, CancellationToken, Task>, CancellationToken)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

public static Task<TResult> SafeInvokeAsync<T1, T2, T3, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, T3 arg3, Func<Exception, T1, T2, T3, CancellationToken, Task> catcher = null, CancellationToken ct = default(CancellationToken))
    where TResult : class, IDisposable

Parameters

initializer Func<TResult>

The function delegate that initializes an object implementing the IDisposable interface.

tester Func<TResult, T1, T2, T3, CancellationToken, Task<TResult>>

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

arg1 T1

The first parameter of the function delegate tester and delegate catcher.

arg2 T2

The second parameter of the function delegate tester and delegate catcher.

arg3 T3

The third parameter of the function delegate tester and delegate catcher.

catcher Func<Exception, T1, T2, T3, CancellationToken, Task>

The function delegate that will handle any exceptions that might have been thrown by tester.

ct CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters

T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

T3

The type of the third parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

SafeInvokeAsync<T1, T2, T3, T4, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, T4, CancellationToken, Task<TResult>>, T1, T2, T3, T4, Func<Exception, T1, T2, T3, T4, CancellationToken, Task>, CancellationToken)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

public static Task<TResult> SafeInvokeAsync<T1, T2, T3, T4, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, T4, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Func<Exception, T1, T2, T3, T4, CancellationToken, Task> catcher = null, CancellationToken ct = default(CancellationToken))
    where TResult : class, IDisposable

Parameters

initializer Func<TResult>

The function delegate that initializes an object implementing the IDisposable interface.

tester Func<TResult, T1, T2, T3, T4, CancellationToken, Task<TResult>>

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

arg1 T1

The first parameter of the function delegate tester and delegate catcher.

arg2 T2

The second parameter of the function delegate tester and delegate catcher.

arg3 T3

The third parameter of the function delegate tester and delegate catcher.

arg4 T4

The fourth parameter of the function delegate tester and delegate catcher.

catcher Func<Exception, T1, T2, T3, T4, CancellationToken, Task>

The function delegate that will handle any exceptions that might have been thrown by tester.

ct CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters

T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

T3

The type of the third parameter of the function delegate tester and delegate catcher.

T4

The type of the fourth parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.

SafeInvokeAsync<T1, T2, T3, T4, T5, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, T4, T5, CancellationToken, Task<TResult>>, T1, T2, T3, T4, T5, Func<Exception, T1, T2, T3, T4, T5, CancellationToken, Task>, CancellationToken)

Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).

public static Task<TResult> SafeInvokeAsync<T1, T2, T3, T4, T5, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, T4, T5, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Func<Exception, T1, T2, T3, T4, T5, CancellationToken, Task> catcher = null, CancellationToken ct = default(CancellationToken))
    where TResult : class, IDisposable

Parameters

initializer Func<TResult>

The function delegate that initializes an object implementing the IDisposable interface.

tester Func<TResult, T1, T2, T3, T4, T5, CancellationToken, Task<TResult>>

The function delegate that is used to ensure that operations performed on TResult abides CA2000.

arg1 T1

The first parameter of the function delegate tester and delegate catcher.

arg2 T2

The second parameter of the function delegate tester and delegate catcher.

arg3 T3

The third parameter of the function delegate tester and delegate catcher.

arg4 T4

The fourth parameter of the function delegate tester and delegate catcher.

arg5 T5

The fifth parameter of the function delegate tester and delegate catcher.

catcher Func<Exception, T1, T2, T3, T4, T5, CancellationToken, Task>

The function delegate that will handle any exceptions that might have been thrown by tester.

ct CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task<TResult>

A task that represents the asynchronous operation. The task result contains the return value of the function delegate initializer if the operations succeeded; otherwise null if the operation failed.

Type Parameters

T1

The type of the first parameter of the function delegate tester and delegate catcher.

T2

The type of the second parameter of the function delegate tester and delegate catcher.

T3

The type of the third parameter of the function delegate tester and delegate catcher.

T4

The type of the fourth parameter of the function delegate tester and delegate catcher.

T5

The type of the fifth parameter of the function delegate tester and delegate catcher.

TResult

The type of the return value of the function delegate initializer.