Show / Hide Table of Contents

Class Promise<T>

Represents a promise that a result of the specified type will be provided at some point in the future

Inheritance
System.Object
Promise<T>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
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 Source

Promise()

Initializes a new instance of the Promise<T> class.

Declaration
public Promise()

Properties

| Improve this Doc View Source

Invoker

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.

| Improve this Doc View Source

IsComplete

Gets a value indicating whether this instance is complete.

Declaration
public virtual bool IsComplete { get; }
Property Value
Type Description
System.Boolean

true if this instance is complete; otherwise, false.

| Improve this Doc View Source

IsRejected

Whether an error occurred causing the promise to be rejected

Declaration
public virtual bool IsRejected { get; }
Property Value
Type Description
System.Boolean
Implements
IPromise.IsRejected
| Improve this Doc View Source

IsResolved

Whether the promise completed successfully

Declaration
public virtual bool IsResolved { get; }
Property Value
Type Description
System.Boolean
Implements
IPromise.IsResolved
| Improve this Doc View Source

PercentComplete

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
IPromise.PercentComplete
| Improve this Doc View Source

Value

The result of the promise. Only valid if IsResolved is true

Declaration
public T Value { get; }
Property Value
Type Description
T
Implements
IPromise<T>.Value
Exceptions
Type Condition
System.NotSupportedException

Methods

| Improve this Doc View Source

Always(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
IPromise<T>.Always(Action)
| Improve this Doc View Source

Cancel()

Cancel the operation

Declaration
public virtual void Cancel()
Implements
ICancelable.Cancel()
| Improve this Doc View Source

CancelTarget<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

cancelTarget for chaining additional calls

Type Parameters
Name Description
C
| Improve this Doc View Source

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
IPromise<T>.Done(Action<T>)
| Improve this Doc View Source

ExecuteCallbacks(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)

| Improve this Doc View Source

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
IPromise<T>.Fail(Action<Exception>)
| Improve this Doc View Source

Notify(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
| Improve this Doc View Source

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
IPromise<T>.Progress(Action<Int32, String>)
| Improve this Doc View Source

Reject(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

| Improve this Doc View Source

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 Source

IPromise.Always(Action)

Declaration
IPromise IPromise.Always(Action callback)
Parameters
Type Name Description
System.Action callback
Returns
Type Description
IPromise
Implements
IPromise.Always(Action)
| Improve this Doc View Source

IPromise.Done(Action<Object>)

Declaration
IPromise IPromise.Done(Action<object> callback)
Parameters
Type Name Description
System.Action<System.Object> callback
Returns
Type Description
IPromise
Implements
IPromise.Done(Action<Object>)
| Improve this Doc View Source

IPromise.Fail(Action<Exception>)

Declaration
IPromise IPromise.Fail(Action<Exception> callback)
Parameters
Type Name Description
System.Action<System.Exception> callback
Returns
Type Description
IPromise
Implements
IPromise.Fail(Action<Exception>)
| Improve this Doc View Source

IPromise.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
IPromise.Progress(Action<Int32, String>)
| Improve this Doc View Source

IPromise.Value

Declaration
object IPromise.Value { get; }
Returns
Type Description
System.Object
Implements
IPromise.Value

Extension Methods

Promises.Cancelled<T>(IPromise<T>, Action<OperationCanceledException>)
Promises.Continue<T, S>(IPromise<T>, Func<T, IPromise<S>>)
Promises.Convert<T, S>(IPromise<T>, Func<T, S>)
Promises.Convert<T, S>(IPromise<T>, Action<T, Promise<S>>, Action<Exception, Promise<S>>)
Promises.Error<T>(IPromise<T>, Action<Exception>)
Promises.Error<TErr, T>(IPromise<T>, Action<TErr>)
Promises.FailOver<T>(IPromise<T>, Func<IPromise<T>>)
Promises.WithInvoker<T>(IPromise<T>, Action<Delegate, Object[]>)
Promises.ToTask<T>(IPromise<T>, CancellationToken)
Promises.GetAwaiter<T>(IPromise<T>)
Promises.ConfigureAwait<T>(IPromise<T>, Boolean)
Promises.Wait<T>(IPromise<T>)

See Also

IPromise<T>
  • Improve this Doc
  • View Source
Back to top Copyright © 2015-2017 Microsoft
Generated by DocFX