Questions tagged [promises]

A promise is essentially an API that returns a future value, or a way to manage callback functions. More technically, a promise is a programming pattern that helps invoking a mechanism that is going to be asynchronous in nature.

See the definition for "promise" on stackoverflow.com which is quite good, verbose and comprehensive.

26 questions
99
votes
1 answer

Is there really a fundamental difference between callbacks and Promises?

When doing single-threaded asynchronous programming, there are two main techniques that I'm familiar with. The most common one is using callbacks. That means passing to the function that acts asynchronously a callback-function as a parameter. When…
Aviv Cohn
  • 21,190
  • 31
  • 118
  • 178
12
votes
3 answers

How does JS Promises works being single threaded

Javascript is single threaded. What I understand from this is if JS i executing on line of code lets say a function. It cannot go to the next line unless that function has been removed from the stack. With that being said, I do not understand, how…
user212699
5
votes
2 answers

How do JavaScript engines convert async/await to promises under the hood?

I'm curious how the async/await syntax is converted to Promises. Maybe I'm just not thinking about it properly, but I don't know how this code would be converted to a Promise: async function myFunc(doAwait) { doSomething(); if (doAwait) { …
dx_over_dt
  • 313
  • 3
  • 9
5
votes
2 answers

Is a promise-aware eventing system desirable?

I'm fully aware that Promises and eventing are both ways to do asynchronous programming, and you can choose either one for a given project. However, in practice, the code base I'm working with is large and we use many 3rd party libraries that…
4
votes
1 answer

What's the relation between Promises and Continuations

I think I understand what Promises are about, and I think I understand what continuations are about, but I still fail to see what their connection is. In what ways do Promises use Continuations. They never return, which is explained by the fact that…
hgiesel
  • 771
  • 1
  • 7
  • 12
4
votes
1 answer

Are Native Promises Still Slower in Node vs Libraries such as Bluebird?

Does this question still apply: Why are native ES6 promises slower and more memory-intensive than bluebird?? In regards to the latest versions of Node.js and EC7?
bloppit
  • 157
  • 1
  • 2
4
votes
1 answer

Are promises functional

Functional programming is often explained to agree with lazy evaluation. As far as I know lazy evaluation means that a method gets called if the evaluator/browser/etc. thinks that is the next best thing to do. I've read about lazy evaluation…
Randy
  • 145
  • 7
4
votes
1 answer

Should I be returning promises from any function that uses them?

Promises is a fairly new pattern for me, so I'm still building my intuition for them. I recently came across a case where some code in an adapter-like bit of code was once synchronous, and then became asynchronous, so promises were…
TwainJ
  • 151
  • 4
3
votes
1 answer

What is the advantage of flattening dependent Promises

I've read that nesting Promise continuations is bad practice. For example, here. GetCustomer().then(customer => { ProcessCustomer(customer).then(processingResult => { console.log(customer); console.log(processingResult); …
Tom Bowers
  • 133
  • 5
3
votes
1 answer

Is there any value in using a Promises library versus ES6 Promises?

I see a lot of NodeJS articles recommending the Bluebird library for promisifying your code and avoiding callback spaghetti. Is there any value in using such a library when using Node 4.2.4+ given that ES6 has native Promises? What can I do with…
codecowboy
  • 599
  • 1
  • 4
  • 8
3
votes
1 answer

Javascript Promise chaining

I recently started working with JS Promises. What I always like to do, is create function, which returns a Promise with the final desired result, but I only do 1 operation/then. Consider something like this (this fetches the versions of an npm…
2
votes
2 answers

Why are Promises not "awaited" by default?

In the latest version of languages like TypeScript or ECMAScript you can use async/await constructs to write code that combines the clean structure of synchronous programming with the performance advantages of asynchronous code. Take this as an…
2
votes
1 answer

How do I achieve non-linear non-dependent control flow using Promises (in server-side ES6)

Coming over from the Java world, I am having trouble translating a multi-threaded approach to IO to the ES6 Promises concept of aysnc IO. Many of the examples I have seen on promises show a linear flow. promiseFunction …
Michael Plautz
  • 394
  • 1
  • 10
1
vote
1 answer

Angular2: Service architecture + error handling

I need support for Angular2 service architectures. I am quite familiar with Angular2 but I don't see the best way to implement services, error handling and their connection with the components. I'm aiming at small-middle-sized Angular2 applications…
Gábor Imre
  • 185
  • 5
1
vote
2 answers

How to check for dangling Promises? (Bluebird.js)

I ran into an issue where I forgot to resolve my promise, leaving the remainder of the chain waiting (Forever). Thankfully in my case I was able to track down the issue in only 10 or so minutes, but I could see this being a really big pain in the…
JasonS
  • 193
  • 6
1
2