What is the equivalent of Bluebird Promise.finally in native ES6 promises? [duplicate]

As of February 7, 2018 Chrome 63+, Firefox 58+, and Opera 50+ support Promise.finally. In Node.js 8.1.4+ (V8 5.8+), the feature is available behind the flag –harmony-promise-finally. The Promise.prototype.finally ECMAScript Proposal is currently in stage 3 of the TC39 process. In the meantime to have promise.finally functionality in all browsers; you can add an additional … Read more

Placement of catch BEFORE and AFTER then

So, basically you’re asking what is the difference between these two (where p is a promise created from some previous code): return p.then(…).catch(…); and return p.catch(…).then(…); There are differences either when p resolves or rejects, but whether those differences matter or not depends upon what the code inside the .then() or .catch() handlers does. What … Read more

How does Bluebird’s util.toFastProperties function make an object’s properties “fast”?

2017 update: First, for readers coming today – here is a version that works with Node 7 (4+): function enforceFastProperties(o) { function Sub() {} Sub.prototype = o; var receiver = new Sub(); // create an instance function ic() { return typeof receiver.foo; } // perform access ic(); ic(); return o; eval(“o” + o); // ensure … Read more

When is .then(success, fail) considered an antipattern for promises?

What’s the difference? The .then() call will return a promise that will be rejected in case the callback throws an error. This means, when your success logger fails, the error would be passed to the following .catch() callback, but not to the fail callback that goes alongside success. Here’s a control flow diagram: To express … Read more

Are there still reasons to use promise libraries like Q or BlueBird now that we have ES6 promises? [closed]

The old adage goes that you should pick the right tool for the job. ES6 promises provide the basics. If all you ever want or need is the basics, then that should/could work just fine for you. But, there are more tools in the tool bin than just the basics and there are situations where … Read more

How to check if an object is a Promise?

How a promise library decides If it has a .then function – that’s the only standard promise libraries use. The Promises/A+ specification has a notion called thenable which is basically “an object with a then method”. Promises will and should assimilate anything with a then method. All of the promise implementation you’ve mentioned do this. … Read more

What is the explicit promise construction antipattern and how do I avoid it?

The deferred antipattern (now explicit-construction anti-pattern) coined by Esailija is a common anti-pattern people who are new to promises make, I’ve made it myself when I first used promises. The problem with the above code is that is fails to utilize the fact that promises chain. Promises can chain with .then and you can return … Read more

How do I access previous promise results in a .then() chain?

Break the chain When you need to access the intermediate values in your chain, you should split your chain apart in those single pieces that you need. Instead of attaching one callback and somehow trying to use its parameter multiple times, attach multiple callbacks to the same promise – wherever you need the result value. … Read more

How do I convert an existing callback API to promises?

Promises have state, they start as pending and can settle to: fulfilled meaning that the computation completed successfully. rejected meaning that the computation failed. Promise returning functions should never throw, they should return rejections instead. Throwing from a promise returning function will force you to use both a } catch { and a .catch. People … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)