Skip to content

ScheduledTask Methods

Represents a host-scheduled durable task.

AbortAsync(string, CancellationToken)

View source
public ValueTask AbortAsync(string reason, CancellationToken cancellationToken = default(CancellationToken))
Administratively aborts the task: the host terminalizes it and its attached descendants as failed with a DurableTaskAbortedException carrying reason, without running further task code.

Parameters

reasonstring
The reason for the abort, recorded as the exception message.
cancellationTokenCancellationToken
A token which abandons waiting for the abort to commit.

Exceptions

System.ArgumentException
reason is null, empty, or whitespace.
System.NotSupportedException
The host doesn't support aborting tasks.

AbortAsyncCore(string, CancellationToken)

virtual
View source
protected virtual ValueTask AbortAsyncCore(string reason, CancellationToken cancellationToken)
Asks the host to abort the task for a validated reason.

Parameters

reasonstring
cancellationTokenCancellationToken

CancelAsync(CancellationToken)

View source
public ValueTask CancelAsync(CancellationToken cancellationToken = default(CancellationToken))
Durably requests cancellation.

Parameters

cancellationTokenCancellationToken

CancelAsync(string?, CancellationToken)

View source
public ValueTask CancelAsync(string? reason, CancellationToken cancellationToken = default(CancellationToken))
Durably requests cancellation carrying reason.

Parameters

reasonstring?
The reason which the task's DurableTaskContext reports, or null for none.
cancellationTokenCancellationToken
A token which abandons waiting for the request to commit.

CancelAsyncCore(string?, CancellationToken)

abstract
protected abstract ValueTask CancelAsyncCore(string? reason, CancellationToken cancellationToken)
Asks the host to cancel the task carrying reason, or no reason when it is null.

Parameters

reasonstring?
cancellationTokenCancellationToken

GetAwaiter

View source
public ScheduledTaskAwaiter GetAwaiter()
Gets an awaiter which waits for successful completion.

GetFeature

virtual
View source
public virtual TFeature? GetFeature<TFeature>()
Returns the feature TFeature through which the task's host describes the task, or null when the host provides none.

Returns

The feature, or null.

GetResponseAsync(CancellationToken)

View source
public Task<DurableTaskResponse> GetResponseAsync(CancellationToken cancellationToken = default(CancellationToken))
Waits for and returns the terminal response.

Parameters

cancellationTokenCancellationToken

GetResponseAsync(PollingOptions, CancellationToken)

View source
public Task<DurableTaskResponse> GetResponseAsync(PollingOptions options, CancellationToken cancellationToken = default(CancellationToken))
Polls and returns the current response.

Parameters

optionsPollingOptions
cancellationTokenCancellationToken

Exceptions

System.NotSupportedException
The calling code runs in a durable task.

GetStatusAsync(PollingOptions, CancellationToken)

View source
public Task<DurableTaskStatus> GetStatusAsync(PollingOptions options = default(PollingOptions), CancellationToken cancellationToken = default(CancellationToken))
Polls the current task status.

Parameters

optionsPollingOptions
cancellationTokenCancellationToken

Exceptions

System.NotSupportedException
The calling code runs in a durable task.

IsCompletedAsync(PollingOptions, CancellationToken)

View source
public Task<bool> IsCompletedAsync(PollingOptions options = default(PollingOptions), CancellationToken cancellationToken = default(CancellationToken))
Polls whether the task has reached a terminal state.

Parameters

optionsPollingOptions
cancellationTokenCancellationToken

Exceptions

System.NotSupportedException
The calling code runs in a durable task.

PollAsyncCore(PollingOptions, CancellationToken)

abstract
protected abstract ValueTask<DurableTaskResponse> PollAsyncCore(PollingOptions options, CancellationToken cancellationToken)
Polls the current host response.

Parameters

optionsPollingOptions
cancellationTokenCancellationToken

Race(IReadOnlyList<ScheduledTask<TResult>>, CancellationToken)

static
View source
public static Task<ScheduledTask<TResult>> Race<TResult>(IReadOnlyList<ScheduledTask<TResult>> tasks, CancellationToken cancellationToken = default(CancellationToken))
Waits for the first scheduled task to complete, requests durable cancellation of every other task, waits until every task is terminal, and returns the first task.

Parameters

tasksIReadOnlyList<ScheduledTask<TResult>>
The tasks, which are captured when this method is called.
cancellationTokenCancellationToken
A token which abandons the wait. It doesn't cancel the tasks.

Returns

The task which completed first, including a task which failed or was canceled. Every task has observed its terminal response, so ScheduledTask, ScheduledTask, and Orleans.Durable.Tasks.ScheduledTask.TryGetResult inspect the winner and the other tasks.

Exceptions

System.ArgumentOutOfRangeException
tasks is empty.

Race(IReadOnlyList<ScheduledTask>, CancellationToken)

static
View source
public static Task<ScheduledTask> Race(IReadOnlyList<ScheduledTask> tasks, CancellationToken cancellationToken = default(CancellationToken))
Waits for the first scheduled task to complete, requests durable cancellation of every other task, waits until every task is terminal, and returns the first task.

Parameters

tasksIReadOnlyList<ScheduledTask>
The tasks, which are captured when this method is called.
cancellationTokenCancellationToken
A token which abandons the wait. It doesn't cancel the tasks.

Returns

The task which completed first, including a task which failed or was canceled. Every task has observed its terminal response, so ScheduledTask, ScheduledTask, and Orleans.Durable.Tasks.ScheduledTask.TryGetResult inspect the winner and the other tasks.

Exceptions

System.ArgumentOutOfRangeException
tasks is empty.

WaitAsync(TimeSpan, CancellationToken)

View source
public Task WaitAsync(TimeSpan timeout, CancellationToken cancellationToken = default(CancellationToken))
Waits for successful completion, and requests durable cancellation of the task once timeout elapses.

Parameters

timeoutTimeSpan
The time to wait before requesting cancellation, which is zero or positive.
cancellationTokenCancellationToken
A token which abandons the wait. It doesn't cancel the task.

Returns

An operation which completes once the task is terminal.

Exceptions

System.ArgumentOutOfRangeException
timeout is negative, including System.Threading.Timeout.InfiniteTimeSpan; await the task to wait without a timeout. Outside a durable execution, timeout also exceeds the longest timer interval which System.Threading.CancellationTokenSource.CancelAfter accepts.
System.TimeoutException
The timeout elapsed, and the task ended canceled.

WaitAsync(CancellationToken)

View source
public ValueTask WaitAsync(CancellationToken cancellationToken = default(CancellationToken))
Waits for successful completion.

Parameters

cancellationTokenCancellationToken

WaitAsyncCore(CancellationToken)

abstract
protected internal abstract ValueTask<DurableTaskResponse> WaitAsyncCore(CancellationToken cancellationToken)
Waits for a terminal host response.

Parameters

cancellationTokenCancellationToken

WaitUntilAsync(DateTimeOffset, CancellationToken)

View source
public Task WaitUntilAsync(DateTimeOffset dueTime, CancellationToken cancellationToken = default(CancellationToken))
Waits for successful completion, and requests durable cancellation of the task once dueTime passes.

Parameters

dueTimeDateTimeOffset
The time at which to request cancellation. A time which has passed times out promptly.
cancellationTokenCancellationToken
A token which abandons the wait. It doesn't cancel the task.

Returns

An operation which completes once the task is terminal.

Exceptions

System.ArgumentOutOfRangeException
Outside a durable execution, the time until dueTime exceeds the longest timer interval which System.Threading.CancellationTokenSource.CancelAfter accepts.
System.TimeoutException
The due time passed, and the task ended canceled.

WhenAllCompleted(IReadOnlyList<ScheduledTask<TResult>>, CancellationToken)

static
View source
public static Task<ScheduledTask<TResult>[]> WhenAllCompleted<TResult>(IReadOnlyList<ScheduledTask<TResult>> tasks, CancellationToken cancellationToken = default(CancellationToken))
Waits until every scheduled task is terminal, and returns the tasks in input order.

Parameters

tasksIReadOnlyList<ScheduledTask<TResult>>
The tasks, which are captured when this method is called.
cancellationTokenCancellationToken
A token which abandons the wait. It doesn't cancel the tasks.

Returns

The tasks, in input order. Each has observed its terminal response, so ScheduledTask, ScheduledTask, and Orleans.Durable.Tasks.ScheduledTask.TryGetResult inspect it.

WhenAllCompleted(IReadOnlyList<ScheduledTask>, CancellationToken)

static
View source
public static Task<ScheduledTask[]> WhenAllCompleted(IReadOnlyList<ScheduledTask> tasks, CancellationToken cancellationToken = default(CancellationToken))
Waits until every scheduled task is terminal, and returns the tasks in input order.

Parameters

tasksIReadOnlyList<ScheduledTask>
The tasks, which are captured when this method is called.
cancellationTokenCancellationToken
A token which abandons the wait. It doesn't cancel the tasks.

Returns

The tasks, in input order. Each has observed its terminal response, so ScheduledTask, ScheduledTask, and Orleans.Durable.Tasks.ScheduledTask.TryGetResult inspect it.

WhenAny(IReadOnlyList<ScheduledTask<TResult>>, CancellationToken)

static
View source
public static Task<ScheduledTask<TResult>> WhenAny<TResult>(IReadOnlyList<ScheduledTask<TResult>> tasks, CancellationToken cancellationToken = default(CancellationToken))
Returns the first scheduled task whose response completes, including failed or canceled durable responses. Wait cancellation and transport failures are propagated, and losing waits are canceled without canceling the durable tasks. Candidates are captured when this method is called.

Parameters

tasksIReadOnlyList<ScheduledTask<TResult>>
cancellationTokenCancellationToken

Exceptions

System.ArgumentOutOfRangeException
tasks is empty.
System.InvalidOperationException
The host's wait for the selected task returned an incomplete response.

WhenAny(IReadOnlyList<ScheduledTask>, CancellationToken)

static
View source
public static Task<ScheduledTask> WhenAny(IReadOnlyList<ScheduledTask> tasks, CancellationToken cancellationToken = default(CancellationToken))
Returns the first scheduled task whose response completes, including failed or canceled durable responses. Wait cancellation and transport failures are propagated, and losing waits are canceled without canceling the durable tasks. Candidates are captured when this method is called.

Parameters

tasksIReadOnlyList<ScheduledTask>
cancellationTokenCancellationToken

Exceptions

System.ArgumentOutOfRangeException
tasks is empty.
System.InvalidOperationException
The host's wait for the selected task returned an incomplete response.

WhenEach(IReadOnlyList<ScheduledTask<TResult>>)

static
View source
public static IAsyncEnumerable<ScheduledTask<TResult>> WhenEach<TResult>(IReadOnlyList<ScheduledTask<TResult>> tasks)
Yields each scheduled task once, in completion order, as it reaches a terminal state.

Parameters

tasksIReadOnlyList<ScheduledTask<TResult>>
The tasks, which are captured when this method is called.

Returns

The tasks in completion order. Each yielded task has observed its terminal response, including a failure or a cancellation, which doesn't fail the enumeration.

WhenEach(IReadOnlyList<ScheduledTask>)

static
View source
public static IAsyncEnumerable<ScheduledTask> WhenEach(IReadOnlyList<ScheduledTask> tasks)
Yields each scheduled task once, in completion order, as it reaches a terminal state.

Parameters

tasksIReadOnlyList<ScheduledTask>
The tasks, which are captured when this method is called.

Returns

The tasks in completion order. Each yielded task has observed its terminal response, including a failure or a cancellation, which doesn't fail the enumeration.