If a function cannot return a value or throw an exception without blocking, it can return a promise instead. A promise is an object that represents the return value or the thrown exception that the function may eventually provide. A promise can also be used as a proxy for a remote object to overcome latency.
On the first pass, promises can mitigate the “Pyramid of Doom”: the situation where code marches to the right faster than it marches forward.
step1(function (value1) {
step2(value1, function(value2) {
step3(value2, function(value3) {
step4(value3, function(value4) {
// Do something with value4
});
});
});
});
This ipm package lets user solve the above problem on ClearBlade platform by letting the use of promises. Note: This library is a modification for ClearBlade platform. There is no support for timeouts and long stacks of promises.
This is an ipm package, which contains one or more reusable assets within the ipm Community. The 'package.json' in this repo is a ipm spec's package.json, here, which is a superset of npm's package.json spec, here.
User just need to import the library in the code service and access it using a Q
Object.
There are numerous example which can be run out of the box. The example service shows one of them.
QPromiseLib
- Core library, accessible as Q
Object.
Note: As mentioned above this library has been modified to be able to support on ClearBlade platform. A diff can be done with the API-Reference code and this library to get exact details.
QExampleAsyncCall
- A simple example showing how to use Q
library for promises.