-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Threading.Tasks
Milestone
Description
TaskCompletionSource<TResult> is an easy to use class to use for deferred result returning Tasks controlled via user code; with coverage for exception and cancellation handling.
However it would be good to have a non-result returning, non-generic version also e.g. TaskCompletionSource with TrySetResult => TrySetCompleted
I often see TaskCompletionSource<object> with TrySetResult(null) used for this purpose, however that is not very clean.
public class TaskCompletionSource
{
public TaskCompletionSource();
public TaskCompletionSource(object? state);
public TaskCompletionSource(TaskCreationOptions creationOptions);
public TaskCompletionSource(object? state, TaskCreationOptions creationOptions);
public Task Task { get; }
public void SetCanceled();
public void SetException(IEnumerable<Exception> exceptions);
public void SetException(Exception exception);
public void SetResult();
public bool TrySetCanceled();
public bool TrySetCanceled(CancellationToken cancellationToken);
public bool TrySetException(IEnumerable<Exception> exceptions);
public bool TrySetException(Exception exception);
public bool TrySetResult();
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Threading.Tasks