TaskHelper
Namespace: PuppeteerSharp.Helpers
public static class TaskHelperTask helper.
Inheritance: object
Properties
Section titled “Properties”DefaultTimeout
Section titled “DefaultTimeout”public static int DefaultTimeout { get; set; }Default timeout.
Value: int
Methods
Section titled “Methods”WhenAllFailFast(Task[])
Section titled “WhenAllFailFast(Task[])”public static Task WhenAllFailFast(this Task[] tasks)Awaits all tasks, but fails immediately if any task fails (like JavaScript’s Promise.all).
Unlike Task%5b%5d) which waits for all tasks to complete before throwing,
this method throws immediately when any task fails or is canceled.
Parameters
| Name | Type | Description |
|---|---|---|
tasks |
Task[] | The tasks to await. |
Returns: Task — A task that completes when all tasks complete successfully.
WithTimeout(Task, Func<Task>, int, CancellationToken)
Section titled “WithTimeout(Task, Func<Task>, int, CancellationToken)”public static Task WithTimeout(this Task task, Func<Task> timeoutAction, int milliseconds = 1000, CancellationToken cancellationToken = default)Cancels the <code class=“paramref”>task</code> after <code class=“paramref”>milliseconds</code> milliseconds.
Parameters
| Name | Type | Description |
|---|---|---|
task |
Task | Task to wait for. |
timeoutAction |
Func<Task> | Action to be executed on Timeout. |
milliseconds |
int | Milliseconds timeout. |
cancellationToken |
CancellationToken | Cancellation token. |
Returns: Task — The task result.
WithTimeout(Task, Func<Task>, TimeSpan, CancellationToken)
Section titled “WithTimeout(Task, Func<Task>, TimeSpan, CancellationToken)”public static Task WithTimeout(this Task task, Func<Task> timeoutAction, TimeSpan timeout, CancellationToken cancellationToken)Cancels the <code class=“paramref”>task</code> after a given <code class=“paramref”>timeout</code> period.
Parameters
| Name | Type | Description |
|---|---|---|
task |
Task | Task to wait for. |
timeoutAction |
Func<Task> | Action to be executed on Timeout. |
timeout |
TimeSpan | The timeout period. |
cancellationToken |
CancellationToken | Cancellation token. |
Returns: Task — The task result.
WithTimeout(Task, int?, Func<TimeSpan, Exception>, CancellationToken)
Section titled “WithTimeout(Task, int?, Func<TimeSpan, Exception>, CancellationToken)”public static Task WithTimeout(this Task task, int? milliseconds = null, Func<TimeSpan, Exception> exceptionFactory = null, CancellationToken cancellationToken = default)Cancels the <code class=“paramref”>task</code> after <code class=“paramref”>milliseconds</code> milliseconds.
Parameters
| Name | Type | Description |
|---|---|---|
task |
Task | Task to wait for. |
milliseconds |
int? | Milliseconds timeout. |
exceptionFactory |
Func<TimeSpan, Exception> | Optional timeout exception factory. |
cancellationToken |
CancellationToken | Cancellation token. |
Returns: Task — The task result.
WithTimeout(Task, TimeSpan, Func<TimeSpan, Exception>, CancellationToken)
Section titled “WithTimeout(Task, TimeSpan, Func<TimeSpan, Exception>, CancellationToken)”public static Task WithTimeout(this Task task, TimeSpan timeout, Func<TimeSpan, Exception> exceptionFactory = null, CancellationToken cancellationToken = default)Cancels the <code class=“paramref”>task</code> after a given <code class=“paramref”>timeout</code> period.
Parameters
| Name | Type | Description |
|---|---|---|
task |
Task | Task to wait for. |
timeout |
TimeSpan | The timeout period. |
exceptionFactory |
Func<TimeSpan, Exception> | Optional timeout exception factory. |
cancellationToken |
CancellationToken | Cancellation token. |
Returns: Task — The task result.
WithTimeout<T>(Task<T>, Action, int)
Section titled “WithTimeout<T>(Task<T>, Action, int)”public static Task<T> WithTimeout<T>(this Task<T> task, Action timeoutAction, int milliseconds = 1000)Cancels the <code class=“paramref”>task</code> after <code class=“paramref”>milliseconds</code> milliseconds.
Type parameters
| Name | Description |
|---|---|
T |
Return type. |
Parameters
| Name | Type | Description |
|---|---|---|
task |
Task<T> | Task to wait for. |
timeoutAction |
Action | Action to be executed on Timeout. |
milliseconds |
int | Milliseconds timeout. |
Returns: Task<T> — The task result.
WithTimeout<T>(Task<T>, Action, TimeSpan)
Section titled “WithTimeout<T>(Task<T>, Action, TimeSpan)”public static Task<T> WithTimeout<T>(this Task<T> task, Action timeoutAction, TimeSpan timeout)Cancels the <code class=“paramref”>task</code> after a given <code class=“paramref”>timeout</code> period.
Type parameters
| Name | Description |
|---|---|
T |
Return type. |
Parameters
| Name | Type | Description |
|---|---|---|
task |
Task<T> | Task to wait for. |
timeoutAction |
Action | Action to be executed on Timeout. |
timeout |
TimeSpan | The timeout period. |
Returns: Task<T> — The task result.
WithTimeout<T>(Task<T>, int?, Func<TimeSpan, Exception>)
Section titled “WithTimeout<T>(Task<T>, int?, Func<TimeSpan, Exception>)”public static Task<T> WithTimeout<T>(this Task<T> task, int? milliseconds = null, Func<TimeSpan, Exception> exceptionFactory = null)Cancels the <code class=“paramref”>task</code> after <code class=“paramref”>milliseconds</code> milliseconds.
Type parameters
| Name | Description |
|---|---|
T |
Task return type. |
Parameters
| Name | Type | Description |
|---|---|---|
task |
Task<T> | Task to wait for. |
milliseconds |
int? | Milliseconds timeout. |
exceptionFactory |
Func<TimeSpan, Exception> | Optional timeout exception factory. |
Returns: Task<T> — The task result.
WithTimeout<T>(Task<T>, TimeSpan, Func<TimeSpan, Exception>)
Section titled “WithTimeout<T>(Task<T>, TimeSpan, Func<TimeSpan, Exception>)”public static Task<T> WithTimeout<T>(this Task<T> task, TimeSpan timeout, Func<TimeSpan, Exception> exceptionFactory = null)Cancels the <code class=“paramref”>task</code> after a given <code class=“paramref”>timeout</code> period.
Type parameters
| Name | Description |
|---|---|
T |
Task return type. |
Parameters
| Name | Type | Description |
|---|---|---|
task |
Task<T> | Task to wait for. |
timeout |
TimeSpan | The timeout period. |
exceptionFactory |
Func<TimeSpan, Exception> | Optional timeout exception factory. |
Returns: Task<T> — The task result.
Made with love by Dario Kondratiuk