Graphics Reference
In-Depth Information
});
});
});
Using promises, we can flatten this to the following (just like we did in this recipe):
Q.fcall(promisedStep1)
then(promisedStep2)
then(promisedStep3)
then(promisedStep4)
then(function (value4) {
// Do something with value4
})
catch(function (error) {
// Handle any error from all above steps
})
done();
If we were to rewrite the Three.js library, we could have used promises in Three.js
internally, but since Three.js already uses callbacks, we had to use the Q.defer()
function provided by Q to convert these callbacks to promises.
There is more...
We only touched a small part of what is possible with the Q promises library. We
used it for synchronous loading, but Q has many other useful features. A very good
starting point is the Q wiki available at https://github.com/kriskowal/q/wiki .
See also
• Just like every recipe that loads resources you have to make sure that you
run it either with a local web server, see the Setting up a local web server us-
ing Python recipe or the Setting up a web server using Node.js recipe, or dis-
able some security settings (see the Solving cross-origin-domain error mes-
sages in Chrome recipe or the Solving cross-origin-domain error messages
Search WWH ::




Custom Search