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.
251
questions
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 ...
20
votes
1
answer
66k
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, ...
14
votes
2
answers
45k
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() ...
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 ...
12
votes
1
answer
494
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 ...
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 ...
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 ...
10
votes
2
answers
24k
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.
<...
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 ...
10
votes
2
answers
514
views
Stack Exchange review 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 ...
10
votes
1
answer
222
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 ...
10
votes
1
answer
283
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 ...
9
votes
1
answer
38k
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:
...
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, ...
8
votes
3
answers
4k
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 ...
8
votes
2
answers
311
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 ...
8
votes
2
answers
770
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 ...
8
votes
3
answers
688
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 ...
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, ...
7
votes
2
answers
278
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 ...
7
votes
1
answer
2k
views
Using a Wrapper Promise
I wrote some code for an application that uses the following pattern:
...
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 ...
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 ...
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 ...
6
votes
1
answer
387
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 ...
6
votes
1
answer
21k
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 ...
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 ...
6
votes
1
answer
998
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 ...
6
votes
1
answer
1k
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.
...
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 ...
6
votes
1
answer
261
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 ...
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:
...
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 ...
6
votes
1
answer
394
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.
...
5
votes
1
answer
13k
views
Fetch: how to deal with a json payload in an error response?
Trying to get https://github.com/github/fetch working with an API that almost always returns a json payload, even when the response is an error:
...
5
votes
4
answers
942
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 ...
5
votes
1
answer
170
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 ...
5
votes
2
answers
867
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 ...
5
votes
1
answer
692
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.
...
5
votes
2
answers
346
views
Full Promise implementation
I have attempted to implement the native Promise object provided by the browser in JavaScript. The code is pretty easy to understand. It supports most of the promise functionalities, such as chaining, ...
5
votes
1
answer
845
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. <...
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 ...
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 ...
5
votes
1
answer
14k
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 ...
5
votes
1
answer
215
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 ...
5
votes
2
answers
1k
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 ...
5
votes
2
answers
262
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 ...
5
votes
1
answer
176
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 <...
5
votes
1
answer
205
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 ...
5
votes
1
answer
938
views
Promise implementation in Python
Recently I made an basic port of the JavaScript Promise construct to Python. Here's the basic code:
...