Add an error callback to the promise
Call if there was an error in a callback
Reject the promise and pass an option value to the reject callbacks
Value to pass to the reject callbacks
Resolve the promise and pass an option value to the success callbacks
Value to pass to the success callbacks
Inspect the current state of a promise
Chain success and reject callbacks after the promise is resolved
Call on resolution of promise
Call on rejection of promise
Returns a new promise that resolves when all the promises passed to it resolve, or rejects when at least 1 promise rejects.
Returns a new promise that resolves when all the promises passed to it resolve, or rejects when at least 1 promise rejects.
Create and reject a Promise with an optional value
An optional value to wrap in a rejected promise
Create and resolve a Promise with an optional value
An optional value to wrap in a resolved promise
Promises are used to do asynchronous work and they are useful for creating a chain of actions. In Excalibur they are used for loading, sounds, animation, actions, and more.
A Promise Chain
Promises can be chained together and can be useful for creating a queue of functions to be called when something is done. The first Promise you will encounter is probably Engine.start which resolves when the game has finished loading.
var game = new ex.Engine(); // perform start-up logic once game is ready game.start().then(function() { // start-up & initialization logic });
Handling errors
You can optionally pass an error handler to Promise.then which will handle any errors that occur during Promise execution.
var game = new ex.Engine(); game.start().then( // success handler function() {}, // error handler function(err) {} );
Any errors that go unhandled will be bubbled up to the browser.