Skip to content
Advertisement

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 call resolve or reject. Therefore the promise you construct will resolve

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 incorrectly.

Rejecting a promise throws “Uncaught (in promise)”

I’m using promises to handle to handle a modal dialog: resolved when the user press the OK button, rejected when cancelled or closed. To resolve and dismiss the modal I use this methods: And when cancel button fires this method within the modal: Everything is working fine and the modal hides, but a console error is logged with this description

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 constructor passes a specific function into your callback,

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 a lot of heated debate regarding those choices. So to

Calling Promise.all throws Promise.all called on non-object?

I’m trying to return promises from a promise and run Promise.all like this: How can I use this kind of Promise.all. I know .then(promises => Promise.all(promises)) works. But, just trying to know why that failed. This happens with Express res.json too. The error message is different, but I think the reason is same. For example: does not work but does.

Async Concurrent Queue with max concurrency

I’m running across a bug with a custom asynchronous queue that calls 10 async functions at a time. I’m initiating the queue with 50 jobs, once first 10 jobs are finished the queue moves to the subsequent 10 until it finishes all. The bug I’m coming across is that once it finishes 50, it restarts with first 5 jobs with

Advertisement