AsyncHelper
Provides helper methods for asynchronous operations, including cancellation support, task conversion, and exception handling.
Методы
public static ValueTask AsValueTask(Task task)
result = AsyncHelper.AsValueTask(task)
Converts a Task to a ValueTask.
- task
- The task to convert.
Возвращает: A ValueTask representing the task.
public static ValueTask AsValueTask<T>(ValueTask<T> valueTask)
result = AsyncHelper.AsValueTask(valueTask)
Awaits the specified ValueTask and returns its result.
- valueTask
- The ValueTask to await.
Возвращает: The result of the ValueTask.
public static ValueTask<T> AsValueTask<T>(Task<T> task)
result = AsyncHelper.AsValueTask(task)
Converts a Task to a ValueTask.
- task
- The task to convert.
Возвращает: A ValueTask representing the task.
public static ValueTask CatchHandle(Func<Task> getTask, CancellationToken token, Action<Exception> handleError, Action<Exception> handleCancel, Action finalizer, bool rethrowErr, bool rethrowCancel)
result = AsyncHelper.CatchHandle(getTask, token, handleError, handleCancel, finalizer, rethrowErr, rethrowCancel)
Executes the task obtained from the provided function, handles errors and cancellation, and optionally rethrows exceptions.
- getTask
- A function that returns a Task.
- token
- The cancellation token to observe.
- handleError
- An action to handle errors.
- handleCancel
- An action to handle cancellation scenarios.
- finalizer
- An action to execute in the finally block.
- rethrowErr
- Indicates whether to rethrow general exceptions.
- rethrowCancel
- Indicates whether to rethrow cancellation exceptions.
Возвращает: A ValueTask representing the asynchronous operation.
public static ValueTask CatchHandle(ValueTask task, CancellationToken token, Action<Exception> handleError, Action<Exception> handleCancel, Action finalizer, bool rethrowErr, bool rethrowCancel)
result = AsyncHelper.CatchHandle(task, token, handleError, handleCancel, finalizer, rethrowErr, rethrowCancel)
Executes the ValueTask, handles errors and cancellation, and optionally rethrows exceptions.
- task
- The ValueTask to execute.
- token
- The cancellation token to observe.
- handleError
- An action to handle errors.
- handleCancel
- An action to handle cancellation scenarios.
- finalizer
- An action to execute in the finally block.
- rethrowErr
- Indicates whether to rethrow general exceptions.
- rethrowCancel
- Indicates whether to rethrow cancellation exceptions.
Возвращает: A ValueTask representing the asynchronous operation.
public static ValueTask CatchHandle(Task task, CancellationToken token, Action<Exception> handleError, Action<Exception> handleCancel, Action finalizer, bool rethrowErr, bool rethrowCancel)
result = AsyncHelper.CatchHandle(task, token, handleError, handleCancel, finalizer, rethrowErr, rethrowCancel)
Executes the task, handles errors and cancellation, and optionally rethrows exceptions.
- task
- The task to execute.
- token
- The cancellation token to observe.
- handleError
- An action to handle errors.
- handleCancel
- An action to handle cancellation scenarios.
- finalizer
- An action to execute in the finally block.
- rethrowErr
- Indicates whether to rethrow general exceptions.
- rethrowCancel
- Indicates whether to rethrow cancellation exceptions.
Возвращает: A ValueTask representing the asynchronous operation.
public static ValueTask CatchHandle(Func<ValueTask> getTask, CancellationToken token, Action<Exception> handleError, Action<Exception> handleCancel, Action finalizer, bool rethrowErr, bool rethrowCancel)
result = AsyncHelper.CatchHandle(getTask, token, handleError, handleCancel, finalizer, rethrowErr, rethrowCancel)
Executes the ValueTask obtained from the provided function, handles errors and cancellation, and optionally rethrows exceptions.
- getTask
- A function that returns a ValueTask.
- token
- The cancellation token to observe.
- handleError
- An action to handle errors.
- handleCancel
- An action to handle cancellation scenarios.
- finalizer
- An action to execute in the finally block.
- rethrowErr
- Indicates whether to rethrow general exceptions.
- rethrowCancel
- Indicates whether to rethrow cancellation exceptions.
Возвращает: A ValueTask representing the asynchronous operation.
public static ValueTask CheckNull(Task task)
result = AsyncHelper.CheckNull(task)
Returns a ValueTask that completes when the provided task is not null.
- task
- The task to check for null.
Возвращает: A ValueTask representing the operation.
public static ValueTask CheckNull(ValueTask? task)
result = AsyncHelper.CheckNull(task)
Returns a ValueTask from the provided nullable ValueTask.
- task
- The nullable ValueTask.
Возвращает: A ValueTask representing the operation.
public static ValueTuple<CancellationTokenSource, CancellationToken> CreateChildToken(CancellationToken token, TimeSpan? delay)
result = AsyncHelper.CreateChildToken(token, delay)
Creates a child cancellation token linked with the provided token, optionally with a delay.
- token
- The parent cancellation token.
- delay
- Optional delay after which the child token cancels.
Возвращает: A tuple containing the newly created CancellationTokenSource and the linked CancellationToken.
public static ControllablePeriodicTimer CreatePeriodicTimer(Func<Task> handler)
result = AsyncHelper.CreatePeriodicTimer(handler)
Creates a periodic timer that can be started, stopped, and have its interval changed.
- handler
- The asynchronous function to be executed periodically.
Возвращает: A ControllablePeriodicTimer instance.
public static ControllablePeriodicTimer CreatePeriodicTimer(Action handler)
result = AsyncHelper.CreatePeriodicTimer(handler)
Creates a periodic timer that can be started, stopped, and have its interval changed.
- handler
- The action to be executed periodically.
Возвращает: A ControllablePeriodicTimer instance.
public static TaskCompletionSource CreateTaskCompletionSource(bool forceAsync)
result = AsyncHelper.CreateTaskCompletionSource(forceAsync)
Creates a new TaskCompletionSource with the specified configuration.
- forceAsync
- If true, uses asynchronous continuations.
Возвращает: A new TaskCompletionSource with the provided configuration.
public static TaskCompletionSource<TValue> CreateTaskCompletionSource<TValue>(bool forceAsync)
result = AsyncHelper.CreateTaskCompletionSource(forceAsync)
Creates a new TaskCompletionSource with the specified configuration.
- forceAsync
- If true, uses asynchronous continuations.
Возвращает: A new TaskCompletionSource with the provided configuration.
public static CancellationTokenSource CreateTimeout(TimeSpan timeout)
result = AsyncHelper.CreateTimeout(timeout)
Creates a cancellation token source that will be canceled after the specified timeout.
- timeout
- The timeout after which the token is canceled.
Возвращает: A tuple containing the CancellationTokenSource and its Token. The caller is responsible for disposing the returned CancellationTokenSource.
public static Task Delay(TimeSpan delay, CancellationToken cancellationToken)
result = AsyncHelper.Delay(delay, cancellationToken)
Creates a delay for the specified time interval.
- delay
- The time interval to wait.
- cancellationToken
- A token to observe while waiting.
Возвращает: A task that completes after the specified time delay.
public static Task<TValue> FromResult<TValue>(TValue value)
result = AsyncHelper.FromResult(value)
Returns a completed task with the specified result.
- value
- The value to be used as the task result.
Возвращает: A task that has completed successfully with the given result.
public static T GetResult<T>(Task task)
result = AsyncHelper.GetResult(task)
Retrieves the result of a completed task.
- task
- The completed task.
Возвращает: The result of the task.
public static ValueTask InvokeAsync(Func<CancellationToken, ValueTask> handler, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync(Func<CancellationToken, Task> handler, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T>(Func<T, CancellationToken, ValueTask> handler, T arg, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg
- The handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T>(Func<T, CancellationToken, Task> handler, T arg, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg
- The handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T>(Func<T, Task> handler, T arg)
result = AsyncHelper.InvokeAsync(handler, arg)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg
- The handler argument.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T>(Func<T, ValueTask> handler, T arg)
result = AsyncHelper.InvokeAsync(handler, arg)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg
- The handler argument.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- arg12
- The twelfth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- arg12
- The twelfth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- arg12
- The twelfth handler argument.
- arg13
- The thirteenth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- arg12
- The twelfth handler argument.
- arg13
- The thirteenth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- arg12
- The twelfth handler argument.
- arg13
- The thirteenth handler argument.
- arg14
- The fourteenth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- arg12
- The twelfth handler argument.
- arg13
- The thirteenth handler argument.
- arg14
- The fourteenth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- arg12
- The twelfth handler argument.
- arg13
- The thirteenth handler argument.
- arg14
- The fourteenth handler argument.
- arg15
- The fifteenth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- arg10
- The tenth handler argument.
- arg11
- The eleventh handler argument.
- arg12
- The twelfth handler argument.
- arg13
- The thirteenth handler argument.
- arg14
- The fourteenth handler argument.
- arg15
- The fifteenth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<TDelegate, TState>(TDelegate handler, TState state, Func<TDelegate, TState, ValueTask> invoke)
result = AsyncHelper.InvokeAsync(handler, state, invoke)
Invokes and awaits every handler in a multicast asynchronous delegate by using the specified state and invocation function.
- handler
- The multicast asynchronous delegate. A delegate is treated as having no handlers.
- state
- The state passed to the invocation function for every handler.
- invoke
- The function that invokes one handler with the specified state.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2>(Func<T1, T2, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2>(Func<T1, T2, CancellationToken, Task> handler, T1 arg1, T2 arg2, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3>(Func<T1, T2, T3, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3>(Func<T1, T2, T3, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4>(Func<T1, T2, T3, T4, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4>(Func<T1, T2, T3, T4, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6>(Func<T1, T2, T3, T4, T5, T6, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6>(Func<T1, T2, T3, T4, T5, T6, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7>(Func<T1, T2, T3, T4, T5, T6, T7, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6, T7>(Func<T1, T2, T3, T4, T5, T6, T7, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8>(Func<T1, T2, T3, T4, T5, T6, T7, T8, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8>(Func<T1, T2, T3, T4, T5, T6, T7, T8, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static Task InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, CancellationToken, Task> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ValueTask InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, CancellationToken, ValueTask> handler, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, CancellationToken cancellationToken)
result = AsyncHelper.InvokeAsync(handler, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, cancellationToken)
Invokes and awaits every handler in the multicast asynchronous delegate.
- handler
- The multicast asynchronous delegate.
- arg1
- The first handler argument.
- arg2
- The second handler argument.
- arg3
- The third handler argument.
- arg4
- The fourth handler argument.
- arg5
- The fifth handler argument.
- arg6
- The sixth handler argument.
- arg7
- The seventh handler argument.
- arg8
- The eighth handler argument.
- arg9
- The ninth handler argument.
- cancellationToken
- The cancellation token passed to every handler.
Возвращает: A task representing all handler invocations.
public static ConfiguredValueTaskAwaitable NoWait(ValueTask task)
result = AsyncHelper.NoWait(task)
Configures the awaiter for the specified ValueTask to not capture the current synchronization context.
- task
- The value task to configure.
Возвращает: A configured awaitable for the value task.
public static ConfiguredTaskAwaitable NoWait(Task task)
result = AsyncHelper.NoWait(task)
Configures the awaiter for the specified Task to not capture the current synchronization context.
- task
- The task to configure.
Возвращает: A configured awaitable for the task.
public static ConfiguredTaskAwaitable<T> NoWait<T>(Task<T> task)
result = AsyncHelper.NoWait(task)
Configures the awaiter for the specified Task to not capture the current synchronization context.
- task
- The task to configure.
Возвращает: A configured awaitable for the task.
public static ConfiguredValueTaskAwaitable<T> NoWait<T>(ValueTask<T> task)
result = AsyncHelper.NoWait(task)
Configures the awaiter for the specified ValueTask to not capture the current synchronization context.
- task
- The value task to configure.
Возвращает: A configured awaitable for the value task.
public static ConfiguredCancelableAsyncEnumerable<T> NoWait<T>(IAsyncEnumerable<T> enumerable)
result = AsyncHelper.NoWait(enumerable)
Configures the awaiter for the specified IAsyncEnumerable to not capture the current synchronization context.
- enumerable
- The asynchronous enumerable to configure.
Возвращает: A configured cancellable asynchronous enumerable.
public static void Run(Func<ValueTask> getTask)
AsyncHelper.Run(getTask)
Executes the provided asynchronous function in a synchronous context.
- getTask
- A function that returns a ValueTask.
public static T Run<T>(Func<ValueTask<T>> getTask)
result = AsyncHelper.Run(getTask)
Executes the provided asynchronous function in a synchronous context and returns the result.
- getTask
- A function that returns a ValueTask{T}.
Возвращает: The result from the asynchronous operation.
public static Task StartPeriodicTimer(Func<Task> handler, TimeSpan start, TimeSpan interval, CancellationToken cancellationToken)
result = AsyncHelper.StartPeriodicTimer(handler, start, interval, cancellationToken)
Starts a periodic timer that executes the specified asynchronous function at the given interval with an initial delay.
- handler
- The asynchronous function to be executed periodically.
- start
- The delay before the first execution.
- interval
- The interval between timer executions.
- cancellationToken
- Optional cancellation token to stop the timer.
Возвращает: A Task representing the timer operation.
public static Task StartPeriodicTimer(Action handler, TimeSpan interval, CancellationToken cancellationToken)
result = AsyncHelper.StartPeriodicTimer(handler, interval, cancellationToken)
Starts a periodic timer that executes the specified action at the given interval.
- handler
- The action to be executed periodically.
- interval
- The interval between timer executions.
- cancellationToken
- Optional cancellation token to stop the timer.
Возвращает: A Task representing the timer operation.
public static Task StartPeriodicTimer(Func<Task> handler, TimeSpan interval, CancellationToken cancellationToken)
result = AsyncHelper.StartPeriodicTimer(handler, interval, cancellationToken)
Starts a periodic timer that executes the specified asynchronous function at the given interval.
- handler
- The asynchronous function to be executed periodically.
- interval
- The interval between timer executions.
- cancellationToken
- Optional cancellation token to stop the timer.
Возвращает: A Task representing the timer operation.
public static Task StartPeriodicTimer(Action handler, TimeSpan start, TimeSpan interval, CancellationToken cancellationToken)
result = AsyncHelper.StartPeriodicTimer(handler, start, interval, cancellationToken)
Starts a periodic timer that executes the specified action at the given interval with an initial delay.
- handler
- The action to be executed periodically.
- start
- The delay before the first execution.
- interval
- The interval between timer executions.
- cancellationToken
- Optional cancellation token to stop the timer.
Возвращает: A Task representing the timer operation.
private static Task StartPeriodicTimerCore(Func<Task> handler, TimeSpan interval, TimeSpan initialDelay, CancellationToken cancellationToken)
result = AsyncHelper.StartPeriodicTimerCore(handler, interval, initialDelay, cancellationToken)
Core implementation for the periodic timer.
- handler
- The asynchronous function to be executed periodically.
- interval
- The interval between timer executions.
- initialDelay
- The delay before the first execution.
- cancellationToken
- Cancellation token to stop the timer.
Возвращает: A Task representing the timer operation.
public static Task StartPeriodicTimer<T>(Action<T> handler, T arg, TimeSpan interval, CancellationToken cancellationToken)
result = AsyncHelper.StartPeriodicTimer(handler, arg, interval, cancellationToken)
Starts a periodic timer that executes the specified action with one argument at the given interval.
- handler
- The action to be executed periodically.
- arg
- The argument passed to the action.
- interval
- The interval between timer executions.
- cancellationToken
- Optional cancellation token to stop the timer.
Возвращает: A Task representing the timer operation.
public static Func<CancellationToken, ValueTask> ToAsync(Action action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
- action
- The synchronous action to convert.
Возвращает: An async function that wraps the action.
public static Func<T, CancellationToken, ValueTask> ToAsync<T>(Action<T> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, CancellationToken, ValueTask> ToAsync<T1, T2>(Action<T1, T2> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, CancellationToken, ValueTask> ToAsync<T1, T2, T3>(Action<T1, T2, T3> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6>(Action<T1, T2, T3, T4, T5, T6> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, T7, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6, T7>(Action<T1, T2, T3, T4, T5, T6, T7> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8>(Action<T1, T2, T3, T4, T5, T6, T7, T8> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, CancellationToken, ValueTask> ToAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> action)
result = AsyncHelper.ToAsync(action)
Converts a synchronous action to an async function with CancellationToken support.
public static TaskCompletionSource<TValue> ToCompleteSource<TValue>(TValue value)
result = AsyncHelper.ToCompleteSource(value)
Creates a TaskCompletionSource that is already completed with the specified value.
- value
- The value to complete the task with.
Возвращает: A TaskCompletionSource completed with the given value.
public static bool TryCompleteFromCompletedTask(TaskCompletionSource tcs, Task task)
result = AsyncHelper.TryCompleteFromCompletedTask(tcs, task)
Attempts to complete the TaskCompletionSource using the state of the completed task.
- tcs
- The TaskCompletionSource to complete.
- task
- The completed task whose state is used.
Возвращает: True if TaskCompletionSource was updated successfully; otherwise, false.
public static ValueTask WhenAll(IEnumerable<ValueTask> tasks)
result = AsyncHelper.WhenAll(tasks)
Awaits all the provided ValueTask tasks.
- tasks
- The collection of ValueTasks to await.
Возвращает: A task representing the asynchronous operation.
public static ValueTask<T[]> WhenAll<T>(IEnumerable<ValueTask<T>> tasks)
result = AsyncHelper.WhenAll(tasks)
Awaits all the provided ValueTask tasks and returns an array of their results.
- tasks
- The collection of ValueTasks to await.
Возвращает: An array of the results from the tasks.
public static Task WhenCanceled(CancellationToken token)
result = AsyncHelper.WhenCanceled(token)
Returns a task that completes when the cancellation token is canceled.
- token
- The cancellation token.
Возвращает: A task that completes when the token is canceled.
public static Task WithCancellation(Task task, CancellationToken cancellationToken)
result = AsyncHelper.WithCancellation(task, cancellationToken)
Awaits the task and supports cancellation by throwing an OperationCanceledException if the cancellation token is triggered.
- task
- The task to await.
- cancellationToken
- The token used to cancel the operation.
public static Task<T> WithCancellation<T>(Task<T> task, CancellationToken cancellationToken)
result = AsyncHelper.WithCancellation(task, cancellationToken)
Awaits the task and supports cancellation by throwing an OperationCanceledException if the cancellation token is triggered.
- task
- The task to await.
- cancellationToken
- The token used to cancel the operation.
Возвращает: A task representing the asynchronous operation that returns a result of type T.
public static IAsyncEnumerable<T> WithEnforcedCancellation<T>(IAsyncEnumerable<T> source, CancellationToken cancellationToken)
result = AsyncHelper.WithEnforcedCancellation(source, cancellationToken)
Returns an asynchronous enumerable that enforces cancellation using the provided token.
- source
- The source asynchronous enumerable.
- cancellationToken
- The cancellation token to observe.
Возвращает: An asynchronous enumerable that throws an exception if cancellation is requested.