Class Promise
Inheritance
System.Object
Promise
Namespace: RSG
Syntax
public class Promise : IPromise, IPendingPromise, IRejectable, IPromiseInfo
Constructors
Promise(Action<Action, Action<Exception>>, Boolean)
Declaration
public Promise(Action<Action, Action<Exception>> resolver, bool isSync = false)
Parameters
| Type |
Name |
Description |
| System.Action<System.Action, System.Action<System.Exception>> |
resolver |
|
| System.Boolean |
isSync |
|
Promise(Boolean)
Declaration
public Promise(bool isSync = false)
Parameters
| Type |
Name |
Description |
| System.Boolean |
isSync |
|
Fields
EnablePromiseTracking
Set to true to enable tracking of promises.
Declaration
public static bool EnablePromiseTracking
Field Value
| Type |
Description |
| System.Boolean |
|
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
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[])
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 All(params IPromise[] promises)
Parameters
| Type |
Name |
Description |
| IPromise[] |
promises |
|
Returns
All(IEnumerable<IPromise>)
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 All(IEnumerable<IPromise> promises)
Parameters
| Type |
Name |
Description |
| System.Collections.Generic.IEnumerable<IPromise> |
promises |
|
Returns
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
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
Delayed(TimeSpan)
Declaration
public static IPromise Delayed(TimeSpan duration)
Parameters
| Type |
Name |
Description |
| System.TimeSpan |
duration |
|
Returns
Done()
Complete the promise. Adds a defualt error handler.
Declaration
Implements
Done(Action)
Completes the promise.
onResolved is called on successful completion.
Adds a default error handler.
Declaration
public void Done(Action onResolved)
Parameters
| Type |
Name |
Description |
| System.Action |
onResolved |
|
Implements
Done(Action, Action<Exception>)
Completes the promise.
onResolved is called on successful completion.
onRejected is called on error.
Declaration
public void Done(Action onResolved, Action<Exception> onRejected)
Parameters
| Type |
Name |
Description |
| System.Action |
onResolved |
|
| System.Action<System.Exception> |
onRejected |
|
Implements
Finally(Action)
Declaration
public IPromise Finally(Action onComplete)
Parameters
| Type |
Name |
Description |
| System.Action |
onComplete |
|
Returns
Implements
GetPendingPromises()
Information about pending promises, useful for debugging.
This is only populated when 'EnablePromiseTracking' is set to true.
Declaration
public static IEnumerable<IPromiseInfo> GetPendingPromises()
Returns
| Type |
Description |
| System.Collections.Generic.IEnumerable<IPromiseInfo> |
|
Progress(Action<Single>)
Declaration
public IPromise Progress(Action<float> onProgress)
Parameters
| Type |
Name |
Description |
| System.Action<System.Single> |
onProgress |
|
Returns
Implements
Race(IPromise[])
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 Race(params IPromise[] promises)
Parameters
| Type |
Name |
Description |
| IPromise[] |
promises |
|
Returns
Race(IEnumerable<IPromise>)
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 Race(IEnumerable<IPromise> promises)
Parameters
| Type |
Name |
Description |
| System.Collections.Generic.IEnumerable<IPromise> |
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 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()
Resolve the promise with a particular value.
Declaration
Implements
Resolved()
Convert a simple value directly into a resolved promise.
Declaration
public static IPromise Resolved()
Returns
ResolveSync()
Declaration
public void ResolveSync()
Sequence(IEnumerable<Func<IPromise>>)
Chain a sequence of operations using promises.
Takes a collection of functions each of which starts an async operation and yields a promise.
Declaration
public static IPromise Sequence(IEnumerable<Func<IPromise>> fns)
Parameters
| Type |
Name |
Description |
| System.Collections.Generic.IEnumerable<System.Func<IPromise>> |
fns |
|
Returns
Sequence(Func<IPromise>[])
Chain a number of operations using promises.
Takes a number of functions each of which starts an async operation and yields a promise.
Declaration
public static IPromise Sequence(params Func<IPromise>[] fns)
Parameters
| Type |
Name |
Description |
| System.Func<IPromise>[] |
fns |
|
Returns
Then(Action)
Declaration
public IPromise Then(Action onResolved)
Parameters
| Type |
Name |
Description |
| System.Action |
onResolved |
|
Returns
Implements
Then(Action, Action<Exception>)
Add a resolved callback and a rejected callback.
Declaration
public IPromise Then(Action onResolved, Action<Exception> onRejected)
Parameters
| Type |
Name |
Description |
| System.Action |
onResolved |
|
| System.Action<System.Exception> |
onRejected |
|
Returns
Implements
Then(Action, Action<Exception>, Action<Single>)
Add a resolved callback, a rejected callback and a progress callback.
Declaration
public IPromise Then(Action onResolved, Action<Exception> onRejected, Action<float> onProgress)
Parameters
| Type |
Name |
Description |
| System.Action |
onResolved |
|
| System.Action<System.Exception> |
onRejected |
|
| System.Action<System.Single> |
onProgress |
|
Returns
Implements
Then(Func<IPromise>)
Add a resolved callback that chains a non-value promise.
Declaration
public IPromise Then(Func<IPromise> onResolved)
Parameters
| Type |
Name |
Description |
| System.Func<IPromise> |
onResolved |
|
Returns
Implements
Then(Func<IPromise>, Action<Exception>)
Add a resolved callback and a rejected callback.
The resolved callback chains a non-value promise.
Declaration
public IPromise Then(Func<IPromise> onResolved, Action<Exception> onRejected)
Parameters
| Type |
Name |
Description |
| System.Func<IPromise> |
onResolved |
|
| System.Action<System.Exception> |
onRejected |
|
Returns
Implements
Then(Func<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<IPromise> onResolved, Action<Exception> onRejected, Action<float> onProgress)
Parameters
| Type |
Name |
Description |
| System.Func<IPromise> |
onResolved |
|
| System.Action<System.Exception> |
onRejected |
|
| System.Action<System.Single> |
onProgress |
|
Returns
Implements
Then<ConvertedT>(Func<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<IPromise<ConvertedT>> onResolved)
Parameters
| Type |
Name |
Description |
| System.Func<IPromise<ConvertedT>> |
onResolved |
|
Returns
Type Parameters
| Name |
Description |
| ConvertedT |
|
Implements
Then<ConvertedT>(Func<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<IPromise<ConvertedT>> onResolved, Func<Exception, IPromise<ConvertedT>> onRejected)
Parameters
| Type |
Name |
Description |
| System.Func<IPromise<ConvertedT>> |
onResolved |
|
| System.Func<System.Exception, IPromise<ConvertedT>> |
onRejected |
|
Returns
Type Parameters
| Name |
Description |
| ConvertedT |
|
Implements
Then<ConvertedT>(Func<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<IPromise<ConvertedT>> onResolved, Func<Exception, IPromise<ConvertedT>> onRejected, Action<float> onProgress)
Parameters
| Type |
Name |
Description |
| System.Func<IPromise<ConvertedT>> |
onResolved |
|
| System.Func<System.Exception, IPromise<ConvertedT>> |
onRejected |
|
| System.Action<System.Single> |
onProgress |
|
Returns
Type Parameters
| Name |
Description |
| ConvertedT |
|
Implements
ThenAll(Func<IEnumerable<IPromise>>)
Chain an enumerable of promises, all of which must resolve.
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<IEnumerable<IPromise>> chain)
Parameters
| Type |
Name |
Description |
| System.Func<System.Collections.Generic.IEnumerable<IPromise>> |
chain |
|
Returns
Implements
ThenAll<ConvertedT>(Func<IEnumerable<IPromise<ConvertedT>>>)
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<IEnumerable<ConvertedT>> ThenAll<ConvertedT>(Func<IEnumerable<IPromise<ConvertedT>>> chain)
Parameters
| Type |
Name |
Description |
| System.Func<System.Collections.Generic.IEnumerable<IPromise<ConvertedT>>> |
chain |
|
Returns
| Type |
Description |
| IPromise<System.Collections.Generic.IEnumerable<ConvertedT>> |
|
Type Parameters
| Name |
Description |
| ConvertedT |
|
Implements
ThenRace(Func<IEnumerable<IPromise>>)
Takes a function that yields an enumerable of promises.
Returns a promise that resolves when the first of the promises has resolved.
Declaration
public IPromise ThenRace(Func<IEnumerable<IPromise>> chain)
Parameters
| Type |
Name |
Description |
| System.Func<System.Collections.Generic.IEnumerable<IPromise>> |
chain |
|
Returns
Implements
ThenRace<ConvertedT>(Func<IEnumerable<IPromise<ConvertedT>>>)
Takes a function that yields an enumerable of promises.
Converts to a value promise.
Returns a promise that resolves when the first of the promises has resolved.
Declaration
public IPromise<ConvertedT> ThenRace<ConvertedT>(Func<IEnumerable<IPromise<ConvertedT>>> chain)
Parameters
| Type |
Name |
Description |
| System.Func<System.Collections.Generic.IEnumerable<IPromise<ConvertedT>>> |
chain |
|
Returns
Type Parameters
| Name |
Description |
| ConvertedT |
|
Implements
ThenSequence(Func<IEnumerable<Func<IPromise>>>)
Chain a sequence of operations using promises.
Reutrn a collection of functions each of which starts an async operation and yields a promise.
Each function will be called and each promise resolved in turn.
The resulting promise is resolved after each promise is resolved in sequence.
Declaration
public IPromise ThenSequence(Func<IEnumerable<Func<IPromise>>> chain)
Parameters
| Type |
Name |
Description |
| System.Func<System.Collections.Generic.IEnumerable<System.Func<IPromise>>> |
chain |
|
Returns
Implements
WithName(String)
Set the name of the promise, useful for debugging.
Declaration
public IPromise WithName(string name)
Parameters
| Type |
Name |
Description |
| System.String |
name |
|
Returns
Implements
Events
UnhandledException
Event raised for unhandled errors.
For this to work you have to complete your promises with a call to Done().
Declaration
public static event EventHandler<ExceptionEventArgs> UnhandledException
Event Type