Class Promise<T>
Represents a promise that a result of the specified type will be provided at some point in the future
Inheritance
Inherited Members
Namespace: Innovator.Client
Assembly: Innovator.Client.dll
Syntax
public class Promise<T> : IPromise<T>, IPromise, ICancelable
Type Parameters
Name | Description |
---|---|
T | Type of data returned by the promise |
Remarks
A promise is very similar to a System.Threading.Tasks.Task and can be awaited just like a task. The API of a promise is very similar to that of a JQuery Promise
To create a promise in a given state, use one of the helper methods from the Promises class such as Resolved<T>(T) or Rejected<T>(Exception).
Constructors
| Improve this Doc View SourcePromise()
Initializes a new instance of the Promise<T> class.
Declaration
public Promise()
Properties
| Improve this Doc View SourceInvoker
Gets or sets the invoker.
Declaration
public Action<Delegate, object[]> Invoker { get; set; }
Property Value
Type | Description |
---|---|
System.Action<System.Delegate, System.Object[]> | The invoker. |
IsComplete
Gets a value indicating whether this instance is complete.
Declaration
public virtual bool IsComplete { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsRejected
Whether an error occurred causing the promise to be rejected
Declaration
public virtual bool IsRejected { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Implements
| Improve this Doc View SourceIsResolved
Whether the promise completed successfully
Declaration
public virtual bool IsResolved { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Implements
| Improve this Doc View SourcePercentComplete
The progress of the promise represented as an integer from 0 to 100
Declaration
public int PercentComplete { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Implements
| Improve this Doc View SourceValue
The result of the promise. Only valid if IsResolved is true
Declaration
public T Value { get; }
Property Value
Type | Description |
---|---|
T |
Implements
Exceptions
Type | Condition |
---|---|
System.NotSupportedException |
Methods
| Improve this Doc View SourceAlways(Action)
Callback to be executed when the promise completes regardless of whether an error occurred
Declaration
public IPromise<T> Always(Action callback)
Parameters
Type | Name | Description |
---|---|---|
System.Action | callback | Callback to be executed |
Returns
Type | Description |
---|---|
IPromise<T> | The current instance for chaining additional calls |
Implements
| Improve this Doc View SourceCancel()
Cancel the operation
Declaration
public virtual void Cancel()
Implements
| Improve this Doc View SourceCancelTarget<C>(C)
Cancels the target.
Declaration
public C CancelTarget<C>(C cancelTarget)where C : ICancelable
Parameters
Type | Name | Description |
---|---|---|
C | cancelTarget | The cancel target. |
Returns
Type | Description |
---|---|
C |
|
Type Parameters
Name | Description |
---|---|
C |
Done(Action<T>)
Callback to be executed when the promise completes successfully
Declaration
public IPromise<T> Done(Action<T> callback)
Parameters
Type | Name | Description |
---|---|---|
System.Action<T> | callback | Callback to be executed with the result of the promise |
Returns
Type | Description |
---|---|
IPromise<T> | The current instance for chaining additional calls |
Implements
| Improve this Doc View SourceExecuteCallbacks(Promise<T>.Condition, Object, Object)
Execute the stored callbacks for the given condition
Declaration
protected void ExecuteCallbacks(Promise<T>.Condition condition, object arg, object arg2 = null)
Parameters
Type | Name | Description |
---|---|---|
Promise.Condition<> | condition | Which call backs to execute |
System.Object | arg | First argument for the callback |
System.Object | arg2 | Second argument for the callback (if applicable) |
Fail(Action<Exception>)
Callback to be executed when the promise encounters an error
Declaration
public IPromise<T> Fail(Action<Exception> callback)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.Exception> | callback | Callback to be executed with the exception of the promise |
Returns
Type | Description |
---|---|
IPromise<T> | The current instance for chaining additional calls |
Implements
| Improve this Doc View SourceNotify(Int32, String)
Notify promise listeners of a change in the progres
Declaration
public void Notify(int progress, string message)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | progress | |
System.String | message |
Progress(Action<Int32, String>)
Callback to be executed when the reported progress changes
Declaration
public IPromise<T> Progress(Action<int, string> callback)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.Int32, System.String> | callback | Callback to be executed with the progress [0, 100] and the message |
Returns
Type | Description |
---|---|
IPromise<T> | The current instance for chaining additional calls |
Implements
| Improve this Doc View SourceReject(Exception)
Mark the promise as having encountered an error
Declaration
public virtual void Reject(Exception error)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | error | Error which was encountered |
Resolve(T)
Mark the promise as having completed successfully providing the requested data
Declaration
public virtual void Resolve(T data)
Parameters
Type | Name | Description |
---|---|---|
T | data | Data which the promise wraps |
Explicit Interface Implementations
| Improve this Doc View SourceIPromise.Always(Action)
Declaration
IPromise IPromise.Always(Action callback)
Parameters
Type | Name | Description |
---|---|---|
System.Action | callback |
Returns
Type | Description |
---|---|
IPromise |
Implements
| Improve this Doc View SourceIPromise.Done(Action<Object>)
Declaration
IPromise IPromise.Done(Action<object> callback)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.Object> | callback |
Returns
Type | Description |
---|---|
IPromise |
Implements
| Improve this Doc View SourceIPromise.Fail(Action<Exception>)
Declaration
IPromise IPromise.Fail(Action<Exception> callback)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.Exception> | callback |
Returns
Type | Description |
---|---|
IPromise |
Implements
| Improve this Doc View SourceIPromise.Progress(Action<Int32, String>)
Declaration
IPromise IPromise.Progress(Action<int, string> callback)
Parameters
Type | Name | Description |
---|---|---|
System.Action<System.Int32, System.String> | callback |
Returns
Type | Description |
---|---|
IPromise |
Implements
| Improve this Doc View SourceIPromise.Value
Declaration
object IPromise.Value { get; }
Returns
Type | Description |
---|---|
System.Object |