Sorry in advance if somebody is wounded by my silly question, but anyway:
I always thought that await
can work properly only with native Promises. But today I encountered that bluebirdjs promises are also properly handled by await
.
My questions are:
1) How and why does await
really work with non-native Promises?
2) How can I implement my own Promise object which will work correctly with await
?
const BluebirdPromise = require('bluebird');
function sleep(mls) {
return new BluebirdPromise(resolve => setTimeout(resolve, mls));
}
async function test() {
await sleep(5000); // waits 5000 mls
console.log('done'); // printed after 5000 mls
}
test();