#promises talk for queensjs 4/11/15
- js is single threaded
- you can add listeners to events, but what if the event happens before you start listening for it?
- handling errors becomes really difficult in other async options
- continuation calling style
- callbacks
- communicating..?
- using threads
finally
invoked at end no matter how the promise resolvesPromise.all
takes an array of promises and creates a promise that fulfills when all of them successfully complete- returned same order as passed in
- native in js es6
- q
- bluebird
- when
- winjs
- rsvpjs
- jquery
- es7 has new features
async function myFunction() {
let result = await somethingThatReturnsAPromise();
console.log(result); // cool, we have a result
}
// or
async function myFunction() {
try {
await somethingThatReturnsAPromise();
} catch (err) {
console.log(err); // oh noes, we got an error
}
}
-
can use them via some libs
- babel
- regenerator
-
every promise returns a new promise (true?)