Class AsyncCompletionSource<TResult>
Represents an asynchronous operation with external completion control. IAsyncCompletionSource<TResult>.
Inherited Members
Namespace: UnityFx.Async
Assembly: UnityFx.Async-netstandard2.0.dll
Syntax
public class AsyncCompletionSource<TResult> : AsyncResult<TResult>, IAsyncContinuation, IEnumerator, IAsyncOperation<TResult>, IAsyncOperation, IAsyncOperationCallbacks, IAsyncCancellable, IAsyncResult, IDisposable, IObservable<TResult>, IAsyncCompletionSource<TResult>
Type Parameters
Name | Description |
---|---|
TResult | Type of the operation result value. |
Constructors
| Improve this Doc View SourceAsyncCompletionSource()
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource()
AsyncCompletionSource(AsyncCallback, Object)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncCallback asyncCallback, object asyncState)
Parameters
Type | Name | Description |
---|---|---|
AsyncCallback | asyncCallback | User-defined completion callback. |
Object | asyncState | User-defined data returned by AsyncState. |
AsyncCompletionSource(Object)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(object asyncState)
Parameters
Type | Name | Description |
---|---|---|
Object | asyncState | User-defined data returned by AsyncState. |
AsyncCompletionSource(AsyncCreationOptions)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncCreationOptions options)
Parameters
Type | Name | Description |
---|---|---|
AsyncCreationOptions | options | The AsyncCreationOptions used to customize the operation's behavior. |
AsyncCompletionSource(AsyncCreationOptions, AsyncCallback, Object)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncCreationOptions options, AsyncCallback asyncCallback, object asyncState)
Parameters
Type | Name | Description |
---|---|---|
AsyncCreationOptions | options | The AsyncCreationOptions used to customize the operation's behavior. |
AsyncCallback | asyncCallback | User-defined completion callback. |
Object | asyncState | User-defined data returned by AsyncState. |
AsyncCompletionSource(AsyncCreationOptions, Object)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncCreationOptions options, object asyncState)
Parameters
Type | Name | Description |
---|---|---|
AsyncCreationOptions | options | The AsyncCreationOptions used to customize the operation's behavior. |
Object | asyncState | User-defined data returned by AsyncState. |
AsyncCompletionSource(AsyncOperationStatus)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncOperationStatus status)
Parameters
Type | Name | Description |
---|---|---|
AsyncOperationStatus | status | Initial value of the Status property. |
AsyncCompletionSource(AsyncOperationStatus, AsyncCallback, Object)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncOperationStatus status, AsyncCallback asyncCallback, object asyncState)
Parameters
Type | Name | Description |
---|---|---|
AsyncOperationStatus | status | Initial value of the Status property. |
AsyncCallback | asyncCallback | User-defined completion callback. |
Object | asyncState | User-defined data returned by AsyncState. |
AsyncCompletionSource(AsyncOperationStatus, Object)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncOperationStatus status, object asyncState)
Parameters
Type | Name | Description |
---|---|---|
AsyncOperationStatus | status | Initial value of the Status property. |
Object | asyncState | User-defined data returned by AsyncState. |
AsyncCompletionSource(AsyncOperationStatus, AsyncCreationOptions)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncOperationStatus status, AsyncCreationOptions options)
Parameters
Type | Name | Description |
---|---|---|
AsyncOperationStatus | status | Initial value of the Status property. |
AsyncCreationOptions | options | The AsyncCreationOptions used to customize the operation's behavior. |
AsyncCompletionSource(AsyncOperationStatus, AsyncCreationOptions, AsyncCallback, Object)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncOperationStatus status, AsyncCreationOptions options, AsyncCallback asyncCallback, object asyncState)
Parameters
Type | Name | Description |
---|---|---|
AsyncOperationStatus | status | Initial value of the Status property. |
AsyncCreationOptions | options | The AsyncCreationOptions used to customize the operation's behavior. |
AsyncCallback | asyncCallback | User-defined completion callback. |
Object | asyncState | User-defined data returned by AsyncState. |
AsyncCompletionSource(AsyncOperationStatus, AsyncCreationOptions, Object)
Initializes a new instance of the AsyncCompletionSource<TResult> class.
Declaration
public AsyncCompletionSource(AsyncOperationStatus status, AsyncCreationOptions options, object asyncState)
Parameters
Type | Name | Description |
---|---|---|
AsyncOperationStatus | status | Initial value of the Status property. |
AsyncCreationOptions | options | The AsyncCreationOptions used to customize the operation's behavior. |
Object | asyncState | User-defined data returned by AsyncState. |
Properties
| Improve this Doc View SourceOperation
Gets the operation being controller by the source.
Declaration
public IAsyncOperation<TResult> Operation { get; }
Property Value
Type | Description |
---|---|
IAsyncOperation<TResult> | The underlying operation instance. |
Methods
| Improve this Doc View SourceGetProgress()
Called when the progress is requested. Default implementation returns 0.
Declaration
protected override float GetProgress()
Returns
Type | Description |
---|---|
Single |
Overrides
Remarks
Make sure that each method call returns a value greater or equal to the previous. It is important for progress reporting consistency.
See Also
| Improve this Doc View SourceOnCancel()
Called when the operation cancellation has been requested. Default implementation does nothing.
Declaration
protected override void OnCancel()
Overrides
See Also
SetRunning()
Transitions the operation to Running state.
Declaration
public void SetRunning()
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the transition fails. |
ObjectDisposedException | Thrown is the operation is disposed. |
See Also
| Improve this Doc View SourceSetScheduled()
Transitions the operation to Scheduled state.
Declaration
public void SetScheduled()
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the transition fails. |
ObjectDisposedException | Thrown is the operation is disposed. |
See Also
| Improve this Doc View SourceTrySetCanceled()
Attempts to transition the underlying IAsyncOperation<TResult> into the Canceled state.
Declaration
public bool TrySetCanceled()
Returns
Type | Description |
---|---|
Boolean | Returns true if the attemp was successfull; false otherwise. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Thrown is the operation is disposed. |
TrySetException(Exception)
Attempts to transition the underlying IAsyncOperation<TResult> into the Faulted state.
Declaration
public bool TrySetException(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
Exception | exception | An exception that caused the operation to end prematurely. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the attemp was successfull; false otherwise. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
ObjectDisposedException | Thrown is the operation is disposed. |
TrySetProgress(Single)
Attempts to set the operation progress value in range [0, 1].
Declaration
public bool TrySetProgress(float progress)
Parameters
Type | Name | Description |
---|---|---|
Single | progress | The operation progress in range [0, 1]. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the attemp was successfull; false otherwise. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
ObjectDisposedException | Thrown is the operation is disposed. |
TrySetResult(TResult)
Attempts to transition the underlying IAsyncOperation<TResult> into the RanToCompletion state.
Declaration
public bool TrySetResult(TResult result)
Parameters
Type | Name | Description |
---|---|---|
TResult | result | The operation result. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the attemp was successfull; false otherwise. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Thrown is the operation is disposed. |
TrySetRunning()
Attempts to transition the underlying operation into the Running state.
Declaration
public bool TrySetRunning()
Returns
Type | Description |
---|---|
Boolean | Returns true if the attemp was successfull; false otherwise. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Thrown is the underlying operation is disposed. |
See Also
| Improve this Doc View SourceTrySetScheduled()
Attempts to transition the underlying operation into the Scheduled state.
Declaration
public bool TrySetScheduled()
Returns
Type | Description |
---|---|
Boolean | Returns true if the attemp was successfull; false otherwise. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Thrown is the underlying operation is disposed. |