Class Promise<PromisedT>
Inheritance
System.Object
Promise<PromisedT>
Namespace: RSG
Syntax
public class Promise<PromisedT> : IPromise<PromisedT>, IPendingPromise<PromisedT>, IRejectable, IPromiseInfo
Type Parameters
Name |
Description |
PromisedT |
|
Constructors
Promise(Action<Action<PromisedT>, Action<Exception>>, Boolean)
Declaration
public Promise(Action<Action<PromisedT>, Action<Exception>> resolver, bool isSync = false)
Parameters
Type |
Name |
Description |
System.Action<System.Action<PromisedT>, System.Action<System.Exception>> |
resolver |
|
System.Boolean |
isSync |
|
Promise(Boolean)
Declaration
public Promise(bool isSync = false)
Parameters
Type |
Name |
Description |
System.Boolean |
isSync |
|
Properties
CurState
Tracks the current state of the promise.
Declaration
public PromiseState CurState { get; }
Property Value
Id
ID of the promise, useful for debugging.
Declaration
Property Value
Type |
Description |
System.Int32 |
|
Implements
isCompleted
Declaration
public bool isCompleted { get; }
Property Value
Type |
Description |
System.Boolean |
|
Implements
IsSync
Declaration
public bool IsSync { get; }
Property Value
Type |
Description |
System.Boolean |
|
Name
Name of the promise, when set, useful for debugging.
Declaration
public string Name { get; }
Property Value
Type |
Description |
System.String |
|
Implements
Methods
All(IPromise<PromisedT>[])
Returns a promise that resolves when all of the promises in the enumerable argument have resolved.
Returns a promise of a collection of the resolved results.
Declaration
public static IPromise<IEnumerable<PromisedT>> All(params IPromise<PromisedT>[] promises)
Parameters
Type |
Name |
Description |
IPromise<PromisedT>[] |
promises |
|
Returns
Type |
Description |
IPromise<System.Collections.Generic.IEnumerable<PromisedT>> |
|
All(IEnumerable<IPromise<PromisedT>>)
Returns a promise that resolves when all of the promises in the enumerable argument have resolved.
Returns a promise of a collection of the resolved results.
Declaration
public static IPromise<IEnumerable<PromisedT>> All(IEnumerable<IPromise<PromisedT>> promises)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<IPromise<PromisedT>> |
promises |
|
Returns
Type |
Description |
IPromise<System.Collections.Generic.IEnumerable<PromisedT>> |
|
Catch(Action<Exception>)
Handle errors for the promise.
Declaration
public IPromise Catch(Action<Exception> onRejected)
Parameters
Type |
Name |
Description |
System.Action<System.Exception> |
onRejected |
|
Returns
Implements
Catch(Func<Exception, PromisedT>)
Handle errors for the promise.
Declaration
public IPromise<PromisedT> Catch(Func<Exception, PromisedT> onRejected)
Parameters
Type |
Name |
Description |
System.Func<System.Exception, PromisedT> |
onRejected |
|
Returns
Implements
ContinueWith(Func<IPromise>)
Declaration
public IPromise ContinueWith(Func<IPromise> onComplete)
Parameters
Type |
Name |
Description |
System.Func<IPromise> |
onComplete |
|
Returns
Implements
ContinueWith<ConvertedT>(Func<IPromise<ConvertedT>>)
Declaration
public IPromise<ConvertedT> ContinueWith<ConvertedT>(Func<IPromise<ConvertedT>> onComplete)
Parameters
Type |
Name |
Description |
System.Func<IPromise<ConvertedT>> |
onComplete |
|
Returns
Type Parameters
Name |
Description |
ConvertedT |
|
Implements
Done()
Complete the promise. Adds a default error handler.
Declaration
Implements
Done(Action<PromisedT>)
Completes the promise.
onResolved is called on successful completion.
Adds a default error handler.
Declaration
public void Done(Action<PromisedT> onResolved)
Parameters
Type |
Name |
Description |
System.Action<PromisedT> |
onResolved |
|
Implements
Done(Action<PromisedT>, Action<Exception>)
Completes the promise.
onResolved is called on successful completion.
onRejected is called on error.
Declaration
public void Done(Action<PromisedT> onResolved, Action<Exception> onRejected)
Parameters
Type |
Name |
Description |
System.Action<PromisedT> |
onResolved |
|
System.Action<System.Exception> |
onRejected |
|
Implements
Finally(Action)
Declaration
public IPromise<PromisedT> Finally(Action onComplete)
Parameters
Type |
Name |
Description |
System.Action |
onComplete |
|
Returns
Implements
Progress(Action<Single>)
Declaration
public IPromise<PromisedT> Progress(Action<float> onProgress)
Parameters
Type |
Name |
Description |
System.Action<System.Single> |
onProgress |
|
Returns
Implements
Race(IPromise<PromisedT>[])
Returns a promise that resolves when the first of the promises in the enumerable argument have resolved.
Returns the value from the first promise that has resolved.
Declaration
public static IPromise<PromisedT> Race(params IPromise<PromisedT>[] promises)
Parameters
Type |
Name |
Description |
IPromise<PromisedT>[] |
promises |
|
Returns
Race(IEnumerable<IPromise<PromisedT>>)
Returns a promise that resolves when the first of the promises in the enumerable argument have resolved.
Returns the value from the first promise that has resolved.
Declaration
public static IPromise<PromisedT> Race(IEnumerable<IPromise<PromisedT>> promises)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<IPromise<PromisedT>> |
promises |
|
Returns
Reject(Exception)
Reject the promise with an exception.
Declaration
public void Reject(Exception ex)
Parameters
Type |
Name |
Description |
System.Exception |
ex |
|
Implements
Rejected(Exception)
Convert an exception directly into a rejected promise.
Declaration
public static IPromise<PromisedT> Rejected(Exception ex)
Parameters
Type |
Name |
Description |
System.Exception |
ex |
|
Returns
RejectSync(Exception)
Declaration
public void RejectSync(Exception ex)
Parameters
Type |
Name |
Description |
System.Exception |
ex |
|
ReportProgress(Single)
Report progress on the promise.
Declaration
public void ReportProgress(float progress)
Parameters
Type |
Name |
Description |
System.Single |
progress |
|
Implements
Resolve(PromisedT)
Resolve the promise with a particular value.
Declaration
public void Resolve(PromisedT value)
Parameters
Type |
Name |
Description |
PromisedT |
value |
|
Implements
Resolved(PromisedT)
Convert a simple value directly into a resolved promise.
Declaration
public static IPromise<PromisedT> Resolved(PromisedT promisedValue)
Parameters
Type |
Name |
Description |
PromisedT |
promisedValue |
|
Returns
ResolveSync(PromisedT)
Declaration
public void ResolveSync(PromisedT value)
Parameters
Type |
Name |
Description |
PromisedT |
value |
|
Then(Action<PromisedT>)
Declaration
public IPromise Then(Action<PromisedT> onResolved)
Parameters
Type |
Name |
Description |
System.Action<PromisedT> |
onResolved |
|
Returns
Implements
Then(Action<PromisedT>, Action<Exception>)
Add a resolved callback and a rejected callback.
Declaration
public IPromise Then(Action<PromisedT> onResolved, Action<Exception> onRejected)
Parameters
Type |
Name |
Description |
System.Action<PromisedT> |
onResolved |
|
System.Action<System.Exception> |
onRejected |
|
Returns
Implements
Then(Action<PromisedT>, Action<Exception>, Action<Single>)
Add a resolved callback, a rejected callback and a progress callback.
Declaration
public IPromise Then(Action<PromisedT> onResolved, Action<Exception> onRejected, Action<float> onProgress)
Parameters
Type |
Name |
Description |
System.Action<PromisedT> |
onResolved |
|
System.Action<System.Exception> |
onRejected |
|
System.Action<System.Single> |
onProgress |
|
Returns
Implements
Then(Func<PromisedT, IPromise>)
Add a resolved callback that chains a non-value promise.
Declaration
public IPromise Then(Func<PromisedT, IPromise> onResolved)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, IPromise> |
onResolved |
|
Returns
Implements
Then(Func<PromisedT, IPromise>, Action<Exception>)
Add a resolved callback and a rejected callback.
The resolved callback chains a non-value promise.
Declaration
public IPromise Then(Func<PromisedT, IPromise> onResolved, Action<Exception> onRejected)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, IPromise> |
onResolved |
|
System.Action<System.Exception> |
onRejected |
|
Returns
Implements
Then(Func<PromisedT, IPromise>, Action<Exception>, Action<Single>)
Add a resolved callback, a rejected callback and a progress callback.
The resolved callback chains a non-value promise.
Declaration
public IPromise Then(Func<PromisedT, IPromise> onResolved, Action<Exception> onRejected, Action<float> onProgress)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, IPromise> |
onResolved |
|
System.Action<System.Exception> |
onRejected |
|
System.Action<System.Single> |
onProgress |
|
Returns
Implements
Then<ConvertedT>(Func<PromisedT, ConvertedT>)
Return a new promise with a different value.
May also change the type of the value.
Declaration
public IPromise<ConvertedT> Then<ConvertedT>(Func<PromisedT, ConvertedT> transform)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, ConvertedT> |
transform |
|
Returns
Type Parameters
Name |
Description |
ConvertedT |
|
Implements
Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>>)
Add a resolved callback that chains a value promise (optionally converting to a different value type).
Declaration
public IPromise<ConvertedT> Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>> onResolved)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, IPromise<ConvertedT>> |
onResolved |
|
Returns
Type Parameters
Name |
Description |
ConvertedT |
|
Implements
Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>>, Func<Exception, IPromise<ConvertedT>>)
Add a resolved callback and a rejected callback.
The resolved callback chains a value promise (optionally converting to a different value type).
Declaration
public IPromise<ConvertedT> Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>> onResolved, Func<Exception, IPromise<ConvertedT>> onRejected)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, IPromise<ConvertedT>> |
onResolved |
|
System.Func<System.Exception, IPromise<ConvertedT>> |
onRejected |
|
Returns
Type Parameters
Name |
Description |
ConvertedT |
|
Implements
Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>>, Func<Exception, IPromise<ConvertedT>>, Action<Single>)
Add a resolved callback, a rejected callback and a progress callback.
The resolved callback chains a value promise (optionally converting to a different value type).
Declaration
public IPromise<ConvertedT> Then<ConvertedT>(Func<PromisedT, IPromise<ConvertedT>> onResolved, Func<Exception, IPromise<ConvertedT>> onRejected, Action<float> onProgress)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, IPromise<ConvertedT>> |
onResolved |
|
System.Func<System.Exception, IPromise<ConvertedT>> |
onRejected |
|
System.Action<System.Single> |
onProgress |
|
Returns
Type Parameters
Name |
Description |
ConvertedT |
|
Implements
ThenAll(Func<PromisedT, IEnumerable<IPromise>>)
Chain an enumerable of promises, all of which must resolve.
Converts to a non-value promise.
The resulting promise is resolved when all of the promises have resolved.
It is rejected as soon as any of the promises have been rejected.
Declaration
public IPromise ThenAll(Func<PromisedT, IEnumerable<IPromise>> chain)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, System.Collections.Generic.IEnumerable<IPromise>> |
chain |
|
Returns
Implements
ThenAll<ConvertedT>(Func<PromisedT, IEnumerable<IPromise<ConvertedT>>>)
Chain an enumerable of promises, all of which must resolve.
Returns a promise for a collection of the resolved results.
The resulting promise is resolved when all of the promises have resolved.
It is rejected as soon as any of the promises have been rejected.
Declaration
public IPromise<IEnumerable<ConvertedT>> ThenAll<ConvertedT>(Func<PromisedT, IEnumerable<IPromise<ConvertedT>>> chain)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, System.Collections.Generic.IEnumerable<IPromise<ConvertedT>>> |
chain |
|
Returns
Type |
Description |
IPromise<System.Collections.Generic.IEnumerable<ConvertedT>> |
|
Type Parameters
Name |
Description |
ConvertedT |
|
Implements
ThenRace(Func<PromisedT, IEnumerable<IPromise>>)
Takes a function that yields an enumerable of promises.
Converts to a non-value promise.
Returns a promise that resolves when the first of the promises has resolved.
Yields the value from the first promise that has resolved.
Declaration
public IPromise ThenRace(Func<PromisedT, IEnumerable<IPromise>> chain)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, System.Collections.Generic.IEnumerable<IPromise>> |
chain |
|
Returns
Implements
ThenRace<ConvertedT>(Func<PromisedT, IEnumerable<IPromise<ConvertedT>>>)
Takes a function that yields an enumerable of promises.
Returns a promise that resolves when the first of the promises has resolved.
Yields the value from the first promise that has resolved.
Declaration
public IPromise<ConvertedT> ThenRace<ConvertedT>(Func<PromisedT, IEnumerable<IPromise<ConvertedT>>> chain)
Parameters
Type |
Name |
Description |
System.Func<PromisedT, System.Collections.Generic.IEnumerable<IPromise<ConvertedT>>> |
chain |
|
Returns
Type Parameters
Name |
Description |
ConvertedT |
|
Implements
WithName(String)
Set the name of the promise, useful for debugging.
Declaration
public IPromise<PromisedT> WithName(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Implements