Skip to content
Advertisement

Tag: q

How do you properly return multiple values from a Promise?

I’ve recently run into a certain situation a couple of times, which I didn’t know how to solve properly. Assume the following code: Now a situation might arise where I would want to have access to amazingData in afterSomethingElse. One obvious solution would be to return an array or a hash from afterSomething, because, well, you can only return one

How to check if an object is a Promise?

Whether it’s an ES6 Promise or a Bluebird Promise, Q Promise, etc. How do I test to see if a given object is a Promise? Answer 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

Aren’t promises just callbacks?

I’ve been developing JavaScript for a few years and I don’t understand the fuss about promises at all. It seems like all I do is change: Which I could use a library like async for anyway, with something like: Which is more code and less readable. I didn’t gain anything here, it’s not suddenly magically ‘flat’ either. Not to mention

What happens if i reject / resolve multiple times in Kriskowal’s q?

I’m studying the promises pattern and using kriskowal’s q for node.js, having this snippet: What if both the parser fails and some_reason is true? Will the execution procede from rejecting through resolving and both promise’s method be called at different times, thus generating a bug? Should i avoid to call reject/resolve multiple times? Answer Since promises can only resolve once

Advertisement