Promise

(in ./Carbon/Promise.lua)

Implements a model for asynchronous tasks via promises.

A type of Promise<T> is a Promise that returns the given type, T.


Methods

class public Promise:New()

Returns Promise

class public Promise:PlacementNew(Promise? out)

Returns Promise

object public Promise:Init()

Returns void

Creates or initializes a Promise.


object public Promise:Catch([function fail])

Returns self

  • optional fail: The function to call if this promise fails.

Syntactical sugar for promise:Then(nil, fail).


object public Promise:Reject(...)

Returns void

  • required ...: A list of parameters to be passed as the result.

Rejects the promise, passing along a set of results.

Counts the promise as a failure.


object public Promise:Resolve(...)

Returns void

  • required ...: A list of parameters to be passed as the result.

Resolves the promise, passing along a set of results.

Counts the promise as a success.


object public Promise:Then([function success, function fail])

Returns self

  • optional success: The function to call if this promise succeeds.
  • optional fail: The function to call if this promise fails.

Registers an action to occur after this promise resolves.


object public Promise:All(...)

Returns Promise

  • required ...: A list of promises to wait for.

Returns a promise that resolves when all of the given promises resolve.


object public Promise:Any(...)

Returns Promise

  • required ...: A list of promises to wait for.

Returns a promise that resolves when any one of the given promises resolves.


object public Promise<T>:Await()

Returns T

Yields until the promise has a result to give.

Can only be called from an asynchronous method.


Properties

[none]