CotC C# SDK for Unity  v1.4.0.1
Making social games is easy !
Properties | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
CotcSdk.Promise< PromisedT > Class Template Reference

Description

Promise of future result, which may fail or succeed. Returned as a result of any asnychronous operation.

Complies to the standard Promise specification: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise

Used throughout most API calls to ease the manipulation of asynchronous methods. See this chapter for a tutorial on how to use promises with the SDK.

Template Parameters
PromisedTExpected result type (in case of success, else an exception is returned).

Properties

static EventHandler< ExceptionEventArgsUnhandledException
 Event raised for unhandled errors. For this to work you have to complete your promises with a call to Done(). More...
 

Public Member Functions

Promise< PromisedT > Catch (Action< Exception > onRejected)
 Catches a failure at that point in the chain. More...
 
void Done (Action< PromisedT > onResolved, Action< Exception > onRejected)
 Put this at the end of a promise chain. It ensures that unhandled exceptions can be delivered properly. More...
 
void Done (Action< PromisedT > onResolved)
 Put this at the end of a promise chain. More...
 
void Done ()
 Put this at the end of a promise chain. It ensures that unhandled exceptions can be delivered properly. More...
 
void Reject (Exception ex)
 Reject this promise (indicate that the process failed for some reason). More...
 
void Resolve (PromisedT value)
 Resolves the promise, i.e. notifies a successful result of the async operation. More...
 
Promise< ConvertedT > Then< ConvertedT > (Func< PromisedT, Promise< ConvertedT >> onResolved)
 Add a resolved callback and a rejected callback. The resolved callback chains a value promise (optionally converting to a different value type). More...
 
Promise< PromisedT > Then (Action< PromisedT > onResolved)
 Registers a block of code to be executed when the promise returns a successful result. More...
 
Promise< PromisedT > Then (Action< PromisedT > onResolved, Action< Exception > onRejected)
 Add a resolved callback and a rejected callback. The resolved callback chains a non-value promise. More...
 
Promise< ConvertedT > Then< ConvertedT > (Func< PromisedT, Promise< ConvertedT >> onResolved, Action< Exception > onRejected)
 Adds a resolved and rejected callback. Allows for chaining (i.e. return another promise, potentially of another type, indicating an operation to be waited for). Example: More...
 
override string ToString ()
 Gets some Promise's stats as a human readable string, like its state and its resolved/rejected callbacks counts. More...
 
Promise Catch (Action< Exception > onRejected)
 Catches a failure at that point in the chain. More...
 
void Done (Action onResolved, Action< Exception > onRejected)
 Put this at the end of a promise chain. It ensures that unhandled exceptions can be delivered properly. More...
 
void Done (Action onResolved)
 Put this at the end of a promise chain. More...
 
void Done ()
 Put this at the end of a promise chain. It ensures that unhandled exceptions can be delivered properly. More...
 
void Reject (Exception ex)
 Reject this promise (indicate that the process failed for some reason). More...
 
void Resolve ()
 Resolves the promise, i.e. notifies a successful result of the async operation. More...
 
Promise< ConvertedT > Then< ConvertedT > (Func< Promise< ConvertedT >> onResolved)
 Add a resolved callback and a rejected callback. The resolved callback chains a value promise (optionally converting to a different value type). More...
 
Promise Then (Action onResolved)
 Registers a block of code to be executed when the promise returns a successful result. More...
 
Promise Then (Action onResolved, Action< Exception > onRejected)
 Add a resolved callback and a rejected callback. The resolved callback chains a non-value promise. More...
 
Promise Then (Func< Promise > onResolved)
 Registers a block of code to be executed when the promise returns a successful result. More...
 
Promise Then (Func< Promise > onResolved, Action< Exception > onRejected)
 Add a resolved callback and a rejected callback. The resolved callback chains a non-value promise. More...
 
Promise< ConvertedT > Then< ConvertedT > (Func< Promise< ConvertedT >> onResolved, Action< Exception > onRejected)
 Adds a resolved and rejected callback. Allows for chaining (i.e. return another promise, potentially of another type, indicating an operation to be waited for). Example: More...
 
override string ToString ()
 Gets some Promise's stats as a human readable string, like its state and its resolved/rejected callbacks counts. More...
 

Static Public Member Functions

static Promise< PromisedT > Rejected (Exception ex)
 Shorthand to create a promise that is already rejected. More...
 
static Promise Rejected (Exception ex)
 Shorthand to create a promise that is already rejected. More...
 

Static Public Attributes

static bool Debug_OutputAllExceptions = true
 Set this to true in order to output any exception to the console, even if it is caught by a .Catch block. Just a helper, never keep it true in production. More...
 

Property Documentation

◆ UnhandledException

EventHandler<ExceptionEventArgs> CotcSdk.Promise< PromisedT >.UnhandledException
staticaddremove

Event raised for unhandled errors. For this to work you have to complete your promises with a call to Done().

Member Function Documentation

◆ Catch() [1/2]

Promise<PromisedT> CotcSdk.Promise< PromisedT >.Catch ( Action< Exception >  onRejected)

Catches a failure at that point in the chain.

Parameters
onRejectedBlock handling the exception.
Returns
Another promise which is rejected under any circumstances: either for the same reason as this one (if the promise is caught further in the chain and this block executes well) or with another exception (if the onRejected block throws an exception). As such, it is highly recommended to provide a .Done() block after your Catch block, so that any exception in the catch body can be propagated to the unhandled exception handler.

◆ Catch() [2/2]

Promise CotcSdk.Promise< PromisedT >.Catch ( Action< Exception >  onRejected)

Catches a failure at that point in the chain.

Parameters
onRejectedBlock handling the exception.
Returns
Another promise which is rejected under any circumstances: either for the same reason as this one (if the promise is caught further in the chain and this block executes well) or with another exception (if the onRejected block throws an exception). As such, it is highly recommended to provide a .Done() block after your Catch block, so that any exception in the catch body can be propagated to the unhandled exception handler.

◆ Done() [1/6]

void CotcSdk.Promise< PromisedT >.Done ( Action< PromisedT >  onResolved,
Action< Exception >  onRejected 
)

Put this at the end of a promise chain. It ensures that unhandled exceptions can be delivered properly.

Parameters
onResolvedExecute upon success of all the chain steps.
onRejectedExecute upon rejection of the promise chain (any failure within the chain).

◆ Done() [2/6]

void CotcSdk.Promise< PromisedT >.Done ( Action  onResolved,
Action< Exception >  onRejected 
)

Put this at the end of a promise chain. It ensures that unhandled exceptions can be delivered properly.

Parameters
onResolvedExecute upon success of all the chain steps.
onRejectedExecute upon rejection of the promise chain (any failure within the chain).

◆ Done() [3/6]

void CotcSdk.Promise< PromisedT >.Done ( Action< PromisedT >  onResolved)

Put this at the end of a promise chain.

Parameters
onResolvedExecute upon success (as is, this is nearly equivalent to providing a simple Then block, except that you can not do further chain the promise. Therefore, it ensures that an exception not handled at that point will never be and allows unhandled exceptions to be delivered properly.

◆ Done() [4/6]

void CotcSdk.Promise< PromisedT >.Done ( )

Put this at the end of a promise chain. It ensures that unhandled exceptions can be delivered properly.

◆ Done() [5/6]

void CotcSdk.Promise< PromisedT >.Done ( Action  onResolved)

Put this at the end of a promise chain.

Parameters
onResolvedExecute upon success (as is, this is nearly equivalent to providing a simple Then block, except that you can not do further chain the promise. Therefore, it ensures that an exception not handled at that point will never be and allows unhandled exceptions to be delivered properly.

◆ Done() [6/6]

void CotcSdk.Promise< PromisedT >.Done ( )

Put this at the end of a promise chain. It ensures that unhandled exceptions can be delivered properly.

◆ Reject() [1/2]

void CotcSdk.Promise< PromisedT >.Reject ( Exception  ex)

Reject this promise (indicate that the process failed for some reason).

Parameters
exException to return as the failure result.

◆ Reject() [2/2]

void CotcSdk.Promise< PromisedT >.Reject ( Exception  ex)

Reject this promise (indicate that the process failed for some reason).

Parameters
exException to return as the failure result.

◆ Rejected() [1/2]

static Promise<PromisedT> CotcSdk.Promise< PromisedT >.Rejected ( Exception  ex)
static

Shorthand to create a promise that is already rejected.

Parameters
exException to reject the promise with.
Returns
A promise that is rejected right away.

◆ Rejected() [2/2]

static Promise CotcSdk.Promise< PromisedT >.Rejected ( Exception  ex)
static

Shorthand to create a promise that is already rejected.

Parameters
exException to reject the promise with.
Returns
A promise that is rejected right away.

◆ Resolve() [1/2]

void CotcSdk.Promise< PromisedT >.Resolve ( PromisedT  value)

Resolves the promise, i.e. notifies a successful result of the async operation.

Parameters
valueResult of the async operation. Caught by subscribers to this promise via a Then block.

◆ Resolve() [2/2]

void CotcSdk.Promise< PromisedT >.Resolve ( )

Resolves the promise, i.e. notifies a successful result of the async operation.

◆ Then() [1/6]

Promise<PromisedT> CotcSdk.Promise< PromisedT >.Then ( Action< PromisedT >  onResolved)

Registers a block of code to be executed when the promise returns a successful result.

Parameters
onResolvedExecuted upon successful result.
Returns
A new promise to be used for chaining (you can Catch an exception that happened in the block for instance.

◆ Then() [2/6]

Promise CotcSdk.Promise< PromisedT >.Then ( Action  onResolved)

Registers a block of code to be executed when the promise returns a successful result.

Parameters
onResolvedExecuted upon successful result.
Returns
A new promise to be used for chaining (you can Catch an exception that happened in the block for instance.

◆ Then() [3/6]

Promise<PromisedT> CotcSdk.Promise< PromisedT >.Then ( Action< PromisedT >  onResolved,
Action< Exception >  onRejected 
)

Add a resolved callback and a rejected callback. The resolved callback chains a non-value promise.

Parameters
onResolvedExecuted upon successful result.
onRejectedExecuted upon failure (promise rejected).
Returns
A promise that can be further chained.

◆ Then() [4/6]

Promise CotcSdk.Promise< PromisedT >.Then ( Action  onResolved,
Action< Exception >  onRejected 
)

Add a resolved callback and a rejected callback. The resolved callback chains a non-value promise.

Parameters
onResolvedExecuted upon successful result.
onRejectedExecuted upon failure (promise rejected).
Returns
A promise that can be further chained.

◆ Then() [5/6]

Promise CotcSdk.Promise< PromisedT >.Then ( Func< Promise< PromisedT > >  onResolved)

Registers a block of code to be executed when the promise returns a successful result.

Parameters
onResolvedExecuted upon successful result.
Returns
A new promise to be used for chaining (you can Catch an exception that happened in the block for instance.

◆ Then() [6/6]

Promise CotcSdk.Promise< PromisedT >.Then ( Func< Promise< PromisedT > >  onResolved,
Action< Exception >  onRejected 
)

Add a resolved callback and a rejected callback. The resolved callback chains a non-value promise.

Parameters
onResolvedExecuted upon successful result.
onRejectedExecuted upon failure (promise rejected).
Returns
A promise that can be further chained.

◆ Then< ConvertedT >() [1/4]

Promise<ConvertedT> CotcSdk.Promise< PromisedT >.Then< ConvertedT > ( Func< PromisedT, Promise< ConvertedT >>  onResolved)

Add a resolved callback and a rejected callback. The resolved callback chains a value promise (optionally converting to a different value type).

Template Parameters
ConvertedTType of the expected result (it should be guessed automatically).
Parameters
onResolvedExecuted upon successful result.
Returns
A new promise from another type.

◆ Then< ConvertedT >() [2/4]

Promise<ConvertedT> CotcSdk.Promise< PromisedT >.Then< ConvertedT > ( Func< Promise< ConvertedT >>  onResolved)

Add a resolved callback and a rejected callback. The resolved callback chains a value promise (optionally converting to a different value type).

Template Parameters
ConvertedTType of the expected result (it should be guessed automatically).
Parameters
onResolvedExecuted upon successful result.
Returns
A new promise from another type.

◆ Then< ConvertedT >() [3/4]

Promise<ConvertedT> CotcSdk.Promise< PromisedT >.Then< ConvertedT > ( Func< PromisedT, Promise< ConvertedT >>  onResolved,
Action< Exception >  onRejected 
)

Adds a resolved and rejected callback. Allows for chaining (i.e. return another promise, potentially of another type, indicating an operation to be waited for). Example:

Promise<int> longIntOperation();
Promise<bool> longBoolOperation();
longIntOperation()
.Then((int result) => {
Debug.Log("Result of longIntOperation: " + result");
return longBoolOperation();
})
.Then((bool result) => {
Debug.Log("Result of longBoolOperation: " + result");
})
.Catch((Exception ex) => {
Debug.LogError("Any of the two operations has failed: " + ex.ToString());
}).Done();
Template Parameters
ConvertedTType of the returned promise (should be guessed automatically).
Parameters
onResolvedExecuted upon successful result.
onRejectedExecuted upon failure (promise rejected).
Returns
A new promise that can be chained as shown in the summary.

◆ Then< ConvertedT >() [4/4]

Promise<ConvertedT> CotcSdk.Promise< PromisedT >.Then< ConvertedT > ( Func< Promise< ConvertedT >>  onResolved,
Action< Exception >  onRejected 
)

Adds a resolved and rejected callback. Allows for chaining (i.e. return another promise, potentially of another type, indicating an operation to be waited for). Example:

Promise<int> longIntOperation();
Promise<bool> longBoolOperation();
longIntOperation()
.Then((int result) => {
Debug.Log("Result of longIntOperation: " + result");
return longBoolOperation();
})
.Then((bool result) => {
Debug.Log("Result of longBoolOperation: " + result");
})
.Catch((Exception ex) => {
Debug.LogError("Any of the two operations has failed: " + ex.ToString());
}).Done();
Template Parameters
ConvertedTType of the returned promise (should be guessed automatically).
Parameters
onResolvedExecuted upon successful result.
onRejectedExecuted upon failure (promise rejected).
Returns
A new promise that can be chained as shown in the summary.

◆ ToString() [1/2]

override string CotcSdk.Promise< PromisedT >.ToString ( )

Gets some Promise's stats as a human readable string, like its state and its resolved/rejected callbacks counts.

Returns
Some Promise's stats as a human readable string.

◆ ToString() [2/2]

override string CotcSdk.Promise< PromisedT >.ToString ( )

Gets some Promise's stats as a human readable string, like its state and its resolved/rejected callbacks counts.

Returns
Some Promise's stats as a human readable string.

Member Data Documentation

◆ Debug_OutputAllExceptions

bool CotcSdk.Promise< PromisedT >.Debug_OutputAllExceptions = true
static

Set this to true in order to output any exception to the console, even if it is caught by a .Catch block. Just a helper, never keep it true in production.