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 ...
13
votes
Stack Exchange review queue notifications
I don't see much benefit to the enum. The Notification.permission string (or the return value of requestPermission()) is already ...
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:
<...
8
votes
Timezone-based VPN-detection
I'm not sure whether it is best to use .then(({browserTimezone, ipTimezone}) => ( ... or replace it with something like ...
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 since ...
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 ...
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:
...
6
votes
Accepted
Timezone-based VPN-detection
Use modern JavaScript
Use async functions rather than .then and .catch callbacks.
Use arrow ...
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 ...
5
votes
Stack Exchange review 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 ...
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.
...
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 ...
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:
...
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 ...
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 ...
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, ...
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 ...
4
votes
Accepted
Read files from a directory using Promises
For the most part, your use of promises is idiomatic. Good work! Most people new to promises fail to chain them and end up with a similar pyramid to your original code.
...
4
votes
Accepted
Read files from a directory using Promises V2
First of all, async code is not a requirement for all Node.js code. It depends on the use case. Async code makes sense if you want to service multiple things concurrently (i.e. HTTP servers, test ...
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 ...
4
votes
Accepted
Upvote/counter in Javascript
Consistency
Sometimes you use snake_case and sometimes you use camelCase: in JavaScript we usually use camel case, it's not mandatory but stick to one. Then, for example, ...
4
votes
Accepted
Javascript class to geocode Dutch addresses
Using Promise when async/await is supported is a sign of an anti-pattern. The only case you ...
4
votes
Extending native JavaScript Promise with cancellation support
You can override the executor and can pass an onCancel function to it like following:
...
4
votes
Accepted
Retry a Promise resolution N times, with a delay between the attempts
Call stack / Job queue / Event queue
Calling an async function does not use the call stack in the way you may be used to.
Rather the async call remains on the ...
4
votes
Accepted
Throttling promise execution (API requests, etc)
The most important advice I can offer is to turn on strictNullChecks and noImplicitAny. Without these settings, TypeScript's ...
4
votes
Nested cross-origin iframes for secure user-configurable javascript tools
From a medium review;
host.html
Not a big fan of inline script tags
Not sure why there are 2 <script> tags, I would merge them
You seem to practice a bit of ...
4
votes
Implementing `Promise.all()`
Good job using const for values, as well as let for re-assignable values like ...
4
votes
Best approach on handling function that returns either a promise or just synchronous code
You really don't want a function sometimes returning a promise and sometimes returning a value. That just makes it difficult for the caller. Instead, if you sometimes have a promise to return, then ...
4
votes
Accepted
Implement jquery like functions addClass, removeClass and delay in Javascript
Mutating built-in prototypes is not a good idea. It's not only inelegant, it can also lead to conflicts when other scripts on the page expect the prototypes to be unmutated. (It can even damage future ...
4
votes
Accepted
await user input with async/await syntax
You should use observables and the myriad of functions available for them. It's called reactive programming, but I think it might fall into the category of functionalish.
An example from memory:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
promise × 250javascript × 212
node.js × 85
asynchronous × 32
ecmascript-6 × 30
async-await × 26
angular.js × 21
typescript × 19
express.js × 16
jquery × 15
ajax × 13
error-handling × 9
api × 9
json × 8
react.js × 8
beginner × 7
mongoose × 7
mongodb × 6
callback × 6
authentication × 5
unit-testing × 4
comparative-review × 4
database × 4
google-maps × 4
firebase × 4