Skip to main content

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.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
104 views

Creating a promise based API, from a message based API

I'm building some software that behind the scenes needs to communicate with hardware via a "message" API, over a named pipe. For example, I can send this message: <?xml version="1.0&...
i.brod's user avatar
  • 125
0 votes
1 answer
95 views

Organizing Parallel Arrays of Promises / Async tasks

I'm struggling a bit for a preferred way to organize a sequence of asynchronous tasks that can be applied in parallel. Say, you are parsing data from many files. In my case I'm using javascript and ...
user949300's user avatar
  • 8,929
7 votes
2 answers
4k views

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(...
dx_over_dt's user avatar
0 votes
0 answers
66 views

Streaming Promises in NodeJS

Imagine a typical HTTP service that does async db queries. If HTTP requests are received more quickly than the db can complete queries (such as because the db disk or network is slow), the Promises ...
squarewav's user avatar
  • 206
-1 votes
1 answer
141 views

Does avoiding Promises and Async leads to clean code?

While applying for a job interview I found this line in requirements. Experience with clean code writing practices like avoiding callback hell like promises, async Does this line make any sense ? ...
ZaidRehman's user avatar
0 votes
3 answers
384 views

If callback function, promises and async/await patterns all can be used to achieve asynchronous behaviour then why don't we stick to one?

As far as I have seen then async/await, callbacks and promises are and can only be used to achieve asynchronous programming. Correct? So my questions are: 1) Is it correct that the former three is ...
CodingManiac's user avatar
-1 votes
3 answers
321 views

Writing elegant promises in Node.js

I am having a real difficult time writing some clean code with a simple user registration/login manager. I am trying to stay out of nesting/callback hell, and am also not seeing any benefit in using ...
jozenbasin's user avatar
13 votes
3 answers
13k views

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. ...
user avatar
3 votes
1 answer
409 views

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....
Tom Bowers's user avatar
0 votes
3 answers
3k views

Which is more readable: early returns, or conditionals? [duplicate]

I’m writing an asynchronous, Promise-returning function. In the processing I test some conditions, and if the conditions pass, the promise should be fulfilled (resolved), but if one fails, then the ...
chharvey's user avatar
  • 264
1 vote
1 answer
1k views

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 ...
Gábor Imre's user avatar
0 votes
1 answer
88 views

Framework accepts Promises or executor functions

When designing a framework API is it better to have something that accepts Promises or have executor functions and have the framework build the promises when needed. The Promise API is defined by ...
Archimedes Trajano's user avatar
1 vote
2 answers
2k views

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 ...
JasonS's user avatar
  • 193
6 votes
1 answer
1k views

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 ...
hgiesel's user avatar
  • 821
5 votes
2 answers
381 views

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 ...
RonJRH's user avatar
  • 59
4 votes
1 answer
3k views

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

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's user avatar
  • 157
2 votes
2 answers
1k views

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 ...
danieleds's user avatar
  • 288
4 votes
1 answer
2k views

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 ...
Randy's user avatar
  • 145
1 vote
1 answer
4k views

Error handlers inside Promise.all

I'm looking at this piece of code and whilst it works, it feels wrong to me. I'm wondering if I am looking at an anti-pattern? The code starts with two promises, getAccounts and getTransactions. On ...
mez.pahlan's user avatar
2 votes
1 answer
116 views

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 ...
Michael Plautz's user avatar
0 votes
3 answers
452 views

Which of these promise methods is considered a best practice?

I have a couple of async method that is basically a yes and no reply isUsernameAvalible() isOnline() isImage() yada yada... you probably get the point by now. As a demonstration... try to think of ...
Endless's user avatar
  • 101
2 votes
3 answers
599 views

Is synchronously inspecting a promise an anti-pattern?

ES6 native promises do not allow you to synchronously check if they're resolved/pending/failed or to extract their value. I sometimes need this functionality and thus I have to code it manually. Is ...
adrianton3's user avatar
3 votes
1 answer
672 views

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 ...
codecowboy's user avatar
4 votes
1 answer
298 views

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 ...
TwainJ's user avatar
  • 151
3 votes
1 answer
209 views

Javascript Promise chaining [closed]

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 ...
Balázs Édes's user avatar
99 votes
1 answer
64k views

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 ...
Aviv Cohn's user avatar
  • 21.5k