33 votes

Using fetch() and a new Promise object to get API results

A few comments: 1) fetch already returns a promise, which means this: ...
elclanrs's user avatar
  • 2,535
24 votes
Accepted

Check if images are loaded (ES6 Promises)

Well, you normally don't want to use the Promise constructor in your higher level code, you want to Promisify as low as possible. So let's create a function that ...
Madara's Ghost's user avatar
14 votes
Accepted

Using async / await with dynamic import() for ES6 modules

Approach 2 does not work because accoring to MDN: import '/modules/my-module.js'; Is how you import a module for Import a ...
Taki's user avatar
  • 608
13 votes

Stack Exchange rev​iew queue notifications

I don't see much benefit to the enum. The Notification.permission string (or the return value of requestPermission()) is already ...
CertainPerformance's user avatar
11 votes
Accepted

Fetch: how to deal with a json payload in an error response?

Note this reads more like a hypothetical question but I'm giving you the benefit of the doubt. Your example is alright, but it has a few issues. I'm going to mostly touch on semantics here, so bear ...
Dan's user avatar
  • 3,738
11 votes
Accepted

Pass Async function to new Promise constructor

There's simply no reason to wrap your existing promise with another promise and no reason to use await or async here either: <...
jfriend00's user avatar
  • 3,948
8 votes
Accepted

Pseudo Promise.all() polyfill

implementation The biggest thing that jumped out at me is your all function takes a callback instead of returning a Promise ...
Thank you's user avatar
  • 349
7 votes
Accepted

Yet Another Todo API

Okay I'm going to be a bit more comprehensive here since I've already read your code quite a few times, and I'm gonna assume that you are on node v6 The setup ...
m0meni's user avatar
  • 382
7 votes
Accepted

Mongoose: find() and count() query

Solution After reviewing many answers, I believe I have two options: Make two queries, like I am doing now, Use a pagination plugin for mongoose My decision was the second one and so I am now using ...
Flame_Phoenix's user avatar
6 votes

Baseball player statistics controller

Bearing in mind that you claim that you do not to maintain this code anymore1, there are a few suggestions I would have about this code: define functions and accept parameters- that should allow the ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
6 votes
Accepted

Parallel and Sequential array looping with async/await

JavaScript's execution model My understanding is that the first one is parallel because the await applies to each invocation of the async lambda that is passed to map. This is not quite right ...
ComFreek's user avatar
  • 751
6 votes
Accepted

Exercise to fetch data from JSON files using ES6 promises

There are lots of things you can do: Use a parameterized function to create the XHR promises, since your three functions are identical other than what they're requesting Use ...
T.J. Crowder's user avatar
6 votes
Accepted

code duplication in conditional Promise

You could move the door.locked check into the door.unlock() function (or into a new function) which would allow you return a promise for both cases: ...
Murray's user avatar
  • 198
5 votes
Accepted

`std::move_as_tuple` and `std::when_all`

(Self-answering for posterity.) There's a major flaw in my above implementation of when_all: It calls .get()! This can cause ...
Quuxplusone's user avatar
  • 19.3k
5 votes
Accepted

Create a person if no duplicate exists

To me it looks like you should move the if (result) into each one of promptUserToPickFromDuplicatePersons, ...
Marc Rohloff's user avatar
  • 3,467
5 votes

Javascript progress bar in succession

Your code already looks pretty clean. Good work! There are only a few things I would recommend changing. Don't define timings in CSS that should be defined in JavaScript. In this specific case using ...
Gerrit0's user avatar
  • 3,456
5 votes

Stack Exchange rev​iew queue notifications

Usability I ran the script on the SO review dashboard to see how it would perform with various numbers. The biggest thing I noticed was that it didn't properly handle numbers greater than 999 since ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
5 votes
Accepted

Passing data from one promise to another using then

You could do like so if you prefer, essentially just pass forward the data i the promises. You could write your own promiseAllObject if you want it to be slightly neater. ...
SomeGuy's user avatar
  • 66
5 votes

await user input with async/await syntax

First of all, I would not use Promises to do event based programming. It is not used like that, so your code will get harder to follow. Also, I would advise you to split up your functions more and ...
MauriceNino's user avatar
4 votes
Accepted

Using JavaScript promises to display weather and location information

$.when(getPosition()) $.when is only used when listening to multiple promises. Since ...
Joseph's user avatar
  • 25.1k
4 votes

Check if images are loaded (ES6 Promises)

Sounds like a use case for Promise.allSettled(). The Promise.allSettled() method returns a promise that resolves after all of ...
AFoeee's user avatar
  • 141
4 votes
Accepted

AngularJS recursive function call with $timeout

You're almost there. But first, a few code smells: ...
Joseph's user avatar
  • 25.1k
4 votes
Accepted

Logging a user in and creating a session

Potential improvements ...
Craig Ayre's user avatar
4 votes

Chaining async functions of a module without Promises

You're basically starting to rewriting promises. I think there are pros and cons: For your solution: Its a little simpler. I would have created a wrapper function around ...
Marc Rohloff's user avatar
  • 3,467
4 votes

Chaining async functions of a module without Promises

I recommend using bluebird for promises; it has a ton of nice features that really improve quality of life and seems to be faster than the alternatives by quite a large margin. (Note: I only briefly ...
tiffon's user avatar
  • 631
4 votes
Accepted

Return a Promise for a JSON POST

Given this method, we don't know which syntax is the more appropriate. Neither is appropriate as both your options employ promise anti-patterns (creating new promises when you can just work with and ...
jfriend00's user avatar
  • 3,948
4 votes

Nested loop with synchronous and asynchronous behavior

First you can make the database container more precise and accessible if you define it like this: ...
char bugs's user avatar
  • 171
4 votes
Accepted

JavaScript / Express error handling w/ promises

There's a big problem here. getUserByEmail() can either return a promise or throw synchronously which is a bad design and very unfriendly for the caller. Instead, ...
jfriend00's user avatar
  • 3,948
4 votes
Accepted

Fetching user details, posts, and comments using promises in ExpressJS

If you use 1 promise, you would encounter a long chain of then method and all of async operations would be executed in sequence style which increases response time. If you create 3 promises, all of ...
tanapoln's user avatar
  • 156
4 votes
Accepted

Function to find user's region based on GPS coordinates

The callback supplied to geocode has a lot of code in it. This becomes difficult to test independently of testing the rest of ...
Dan's user avatar
  • 3,738

Only top scored, non community-wiki answers of a minimum length are eligible