As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [promise]

"Promises" are a particular tactic for deferred computing, suitable for several styles of concurrency: thread and event loop concurrency for local computation, and both synchronous and asynchronous remote messaging.

Filter by
Sorted by
Tagged with
22 votes
1 answer
15k views

Simple Async Google Maps initializer with AngularJS

Here is a simple reusable AngularJS factory I came up with to initialize Google Maps Asynchronously, which somehow does not seem ...
Dmitri Zaitsev's user avatar
20 votes
1 answer
64k views

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

I've written an ES6 function using the new fetch() API and returning a new resolved promise with a data object or a rejected promise with an error subclass. I'm pretty new to both ES6 and Promises, ...
Ben Hoyt's user avatar
  • 589
14 votes
2 answers
29k views

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

I am experimenting with the best way to standardise my dynamic import() expressions when importing javascript modules. import() ...
Rounin's user avatar
  • 409
12 votes
2 answers
2k views

Simple AngularJS controller for REST API

We record software builds from our build machine into a database and for practice purposes I'm building a little web dashboard for it. The API is REST (WebApi) and provides access to query for ...
ChrisWue's user avatar
  • 20.1k
12 votes
1 answer
461 views

Pledge: Promise-like entities design goals experiment

Background I was writing a promises/a+ implementation, just for fun. About halfway through I decided it wasn't that fun after all, so I decided to do something a little different. Thinking of ...
Dagg's user avatar
  • 4,531
11 votes
2 answers
4k views

NodeJS broker between MongoDB and RabbitMQ

I wrote a small program that aims to take some data from the MongoDB database and put them in the RabbitMQ queue. I tried to use only promise style but I am a beginner in JavaScript. Could you please ...
Julio's user avatar
  • 113
11 votes
2 answers
2k views

Implementing JQuery style 'deferred' and 'promise' in C#

I like the pattern of the jQuery Deferred object. I like how you can call Resolve any number of times, but the listening objects will only be notified once. I also ...
Andrew Shepherd's user avatar
10 votes
2 answers
15k views

Caching/memoizing promise results

I'm wondering what the best approach might be. One approach is to chain cachedPromise and "regular", thus, if cachedPromise ...
shabunc's user avatar
  • 233
10 votes
2 answers
476 views

Stack Exchange rev​iew queue notifications

A couple of days ago a user in chat asked us to spend more time in the queues. Kick starting my desire to get notifications for new items in the queues. Reviewing the queues has been something I've ...
Peilonrayz's user avatar
  • 42.3k
10 votes
1 answer
220 views

Baseball player statistics controller

I'm somewhat new to JavaScript and AngularJS, and read in Doug Crockford's book that hoisted function declarations can lead to issues. If you have any pointers on how to structure my file, those would ...
dusk's user avatar
  • 101
10 votes
1 answer
268 views

Nested cross-origin iframes for secure user-configurable javascript tools

Context I'm trying to build a system in which a tool (the Client) will generate a header to be used as part of an HTTP request from the user's browser. The user should be able to choose their own ...
ShapeOfMatter's user avatar
9 votes
2 answers
23k views

Check if images are loaded (ES6 Promises)

I wrote a small function that checks if an image or multiple images are loaded. For that purpose, I decided to use ES6 promises, but I'm not really sure if my way of handling errors is the best way. <...
mrksbnch's user avatar
  • 257
9 votes
1 answer
37k views

Mongoose: find() and count() query

Background I have a query in Mongoose that finds a set of objects, and then returns these said objects together with the total number of them: ...
Flame_Phoenix's user avatar
9 votes
1 answer
2k views

Node module using promises and the revealing module pattern

Can someone give me some feedback on this pattern? I am writing a node.js module that connects to a remote API, caches JSON, returns it as output. I have a cli wrapper script that uses the module, ...
Sammers's user avatar
  • 93
8 votes
3 answers
3k views

await user input with async/await syntax

for clarity: moved here from stackoverflow after being pointed to Code Review being the better place for this question I love async/await and Promises since I got my hands on them. And I might be ...
gaugau's user avatar
  • 191
8 votes
2 answers
301 views

Yet Another Todo API

I've been on an adventure trying to learn NodeJs and put together a stack that I'd be happy to put into production if one day my team said to me "Let's build it in Node!". What we have here is your ...
RubberDuck's user avatar
  • 30.8k
8 votes
2 answers
716 views

Function to find user's region based on GPS coordinates

I've made an algorithm/ function to get a user's region based on their GPS coordinates. It primarily looks for big cites and counties for the region and the state for the outer region eg. orange ...
Rachel Dockter's user avatar
8 votes
3 answers
663 views

Node.js module using Promises (client for KeePassHttp)

This is my first Node module, as well as the first time using Promises in Javascript. It is a client for the KeePass plugin "KeePassHTTP" to expose passwords securely, which I am planning on using to ...
michoel's user avatar
  • 133
8 votes
2 answers
3k views

Sails.js controller method for an admin to update a user account

I am new to Sails.js, Node.js, and web application development in general. My current understanding is that well-written controllers should be "skinny" meaning they should be as simple as possible, ...
Adam's user avatar
  • 191
7 votes
2 answers
260 views

Extending Mojo::Promise

First time poster, be gentle. I wanted something similar to Mojo::Promise->all, except with an option to discard certain rejected (or, I guess, resolved) promises dependent on rejection value, as ...
robut's user avatar
  • 173
7 votes
1 answer
2k views

Using a Wrapper Promise

I wrote some code for an application that uses the following pattern: ...
aebabis's user avatar
  • 123
7 votes
1 answer
2k views

Prevent multiple async calls from all attempting to refresh an expired OAuth token

I have some code that needs to access an API that requires OAuth authorization in the form of a token, and every time the token expires, it needs to be refreshed. I made a function called ...
m0meni's user avatar
  • 382
6 votes
2 answers
11k views

Pseudo Promise.all() polyfill

A few years back I interviewed with a company for a Javascript position. After a couple of warm-up challenges I was presented with this: Please write a function that calls back with ...
481b8423202598ecfb233c5fa68caf's user avatar
6 votes
2 answers
10k views

Unit testing a click event with asynchronous content

I'm writing unit tests for a web application that has quite a lot of UI interactions. I would like some feedback regarding on how to handle click events with asynchronous code. My goal here is to ...
Johan's user avatar
  • 631
6 votes
1 answer
376 views

Exercise to fetch data from JSON files using ES6 promises

I did an exercise (self-imposed) promise fetching some data from placeholder JSON files on https://jsonplaceholder.typicode.com/. The exercise in my opinion is finished, but I can't shake the feeling ...
Krešimir Čoko's user avatar
6 votes
1 answer
18k views

Parallel and Sequential array looping with async/await

Are these good implementations of parallel and sequential "extension" methods, and do they accomplish what I think they do? My understanding is that the first one is parallel because the await ...
Dave Cousineau's user avatar
6 votes
1 answer
4k views

NodeJS and Express with Promises

I'm relatively new to NodeJS and Express, and I've recently run into the pyramid of Doom while doing stuff that requires multiple steps. I've found that promises are very promising indeed. But I ...
jhenriquez's user avatar
6 votes
1 answer
975 views

A simple weather app in Node.js

while practicing Promises, I ended up with a simple weather application which works on the command line. I would highly appreciate it if you can point out any flaws ...
codez's user avatar
  • 959
6 votes
1 answer
921 views

Jest unit test that handles a wrapped Promise

I've wrapped an imported function (a promise) and attempted to write unit tests that bring my codebase to 100% coverage. ...
ilrein's user avatar
  • 161
6 votes
1 answer
1k views

Detecting gyroscope data using promises

In a plugin that I am currently authoring, I am using a function to check whether the device provides gyroscopic data. Although intuitively this can be easily resolved by checking the value of ...
Terry's user avatar
  • 185
6 votes
1 answer
260 views

Structuring functions receiving and returning promises?

I keep running into the same pattern with code using promises in javascript. When writing a function which takes a promise and returns a promise, obviously I want to reject the promise I'm returning ...
warp's user avatar
  • 163
6 votes
1 answer
5k views

Multiple jQuery promises

I'm starting to reuse this pattern, and was wondering if there was a more succinct/clear way to write it. Given a function foo taking a callback argument: ...
Gijs's user avatar
  • 161
6 votes
1 answer
3k views

Asynchronous iterator for AngularJS

I wrote this as a convenient way to batch together multiple, repetitive AJAX calls. I was working in angular at the time, so I use the $q service, but I'm sure it ...
Chris's user avatar
  • 163
6 votes
1 answer
378 views

Secret Santa Application : Practical Interview Test

I was given a practical task as part of an interview for a front-end developer position. There is a follow up interview and I'm looking for some constructive criticism / tough love to help me prepare. ...
brianf's user avatar
  • 171
5 votes
4 answers
938 views

Chaining async functions of a module without Promises

I know that promises are the current recommended way to go for asynchronous chaining but, every time I use promises, I don't feel as comfortable as I wish. All that "then" statements and managing ...
Siegfried's user avatar
5 votes
1 answer
167 views

Deleting a section of a website using Ajax

I am currently writing a decent amount of ajax to help me delete a section of a website. It's already becoming a pretty big piece of code, I wondered if it were possible to compact a section of my ...
099's user avatar
  • 337
5 votes
2 answers
817 views

Upvote/counter in Javascript

Looking to improve building UI in pure ES6. This is the pattern I have adopted and has worked fairly well. This code increments the count, sets a data attribute to toggle the button, and issues a ...
cpk's user avatar
  • 153
5 votes
1 answer
691 views

Angular promise in service

I'm new with Angular promise and I would like to know how to improve my code. I have a service which preload media or data by calling an API. The media API return an array of urls to preload. ...
Tib's user avatar
  • 153
5 votes
1 answer
774 views

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

Working with futures and .then, I keep running into the problem of needing to "capture by move" in a lambda. In fact, not only that, but when implementing e.g. <...
Quuxplusone's user avatar
  • 19.2k
5 votes
2 answers
1k views

Using JavaScript promises to display weather and location information

This is the first time I'm trying to use promises in JavaScript so I'm not sure if I have done it correctly, but it seems to work. The problem is that I have ended up with a "nested ...
Veronika's user avatar
5 votes
2 answers
2k views

Extending native JavaScript Promise with cancellation support

Updated, below is a more current and simple version of this. Also, if you track the progress of TC39's "ECMAScript Cancellation" proposal, this thread might be worth checking out. I'm ...
noseratio - open to work's user avatar
5 votes
1 answer
13k views

Java 8 CompletableFuture - fan out implementation

I was wondering what is the best way to implement a fan out type of functionality with Java 8 Completable future. I recently rewrote a function that had a bunch of old ...
Feras's user avatar
  • 213
5 votes
1 answer
205 views

Cloud Function: Deleting from both Firestorage and Firestore in a kind of "batch"

I've written code that deletes a "post" the user has sent with my Android app. A "post" is made of an image (stored in Firestorage) named A, of a Firestore document named B which is the user UID (this ...
JarsOfJam-Scheduler's user avatar
5 votes
2 answers
934 views

Non-polling implementation of std::when_any()

The following — I claim — is a implementation of when_any from the C++ Concurrency TS, except without all the baggage around ...
Quuxplusone's user avatar
  • 19.2k
5 votes
2 answers
239 views

Asynchronous JavaScript to fetch remote JSON data with promises and generators

I am trying to figure out how to do async calls using promises and generators (without 3rd party libraries). Most of the examples I found on the Internet are either incomplete or confusing (at least ...
ArminMeth's user avatar
  • 155
5 votes
1 answer
171 views

Promises with Express/Mongoose to send comment notifications

I'm building the backend for a mobile app project. Below is my createComment controller. The challenge for me is that I want to send notifications out to the <...
bloppit's user avatar
  • 181
5 votes
1 answer
176 views

Resource closing in a promise chain

This is some code that fetches a result from a database. It connects, makes a query, processes the query, then has to close the DB (under all possible code paths) and return the result. It seems ...
jfriend00's user avatar
  • 3,918
5 votes
1 answer
892 views

Promise implementation in Python

Recently I made an basic port of the JavaScript Promise construct to Python. Here's the basic code: ...
Vikram Durai's user avatar
5 votes
1 answer
1k views

Using $q in Angular JS to pass navigator geo JSON from factory to controller

This code is used to get the users location and deliver it as a resource to the controller. The aim is to have this data shared across multiple controllers in the application. So far this does deliver ...
zia grosvenor's user avatar
5 votes
1 answer
133 views

Reading the contents at three URLs using Promises

I'm learning promises and now I'm trying to figure out if something in this code can be improved. This code is expected 3 urls and then async parallel calls should be done. When all requests are ...
Max Grigoriev's user avatar

1
2 3 4 5 6