Docs

Everything You Need to Know

Promises

Intro

Truck Engine

In JavaScript callbacks are used to handle the return of operations. But suppose an operation might take some undertinable amount of time. How would you deal with it? Write a timer? Or put a callback inside the callback. In complex situations this can lead to timers inside timers and deeply nested callbacks.

Promises provide an alternative to this. You create a promise that gets returned when the operation completes. When the promise is resolved, you can handle that, or if the promise gets rejected, you can handle that as well. Promise put you back in charge of comlex asynchronous operations.

Currently all modern browsers support promises, but for the older ones that do not, Truck provides a polyfill.

Promises are easy to use. In fact Truck uses promises for Fetch and Box because they are by nature asynch opertions.

Please read the next sub-section Use for more details on how to use promises.