Skip to content

Tag: promise

Implementation of Promise.race()

I came across an implementation of the Promise.race() method in JavaScript, which works as expected, but doesn’t make much sense to me. How does the forEach loop end up assigning a specific promise’s functions? Answer By definition a promise resolves / rejects only once, no matter how often you ca…

Typescript Promise rejection type

How do I set the type of the rejection of my promise? Let’s say I do: Let’s say I want to reject with a number. But I cannot set the type; I can pass whatever I want to the reject here. Moreover, when using this promise, I want to have compiling error if I use the rejection response type incorrect…

Promise.resolve vs resolve

I have this code: And It resolves promise after one second going to then and console.warning ‘First then!’. But when I change line: for It won’t work. Some idea why ? Also tried But it also doesn’t work. I don’t know why. Can you help me understand it? Answer The new Promise cons…

ES6 native Promise from Factory Function

I’m doing a deep dive into ES6 native Promises. Along the way I came across some articles that quote Douglas Crockford design choices regarding not using things like new, Object.create, this, etc. Some people are advocating the use of Factory Functions over constructors. I have also learnt that there is…