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
5
votes
1answer
138 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 ...
2
votes
2answers
53 views

Blog API implementation in node.js

This code is from my blog project. This project is almost done. This is working well. I can create new posts and update and display all saved posts. ...
3
votes
1answer
97 views

Wrap async method in a way that the method is invoked only once for all calls that occur while the first of them is not resolved

Imagine we have a function that returns a Promise, ie call a GET endpoint of an api and return the response data. ...
1
vote
0answers
15 views

Calling promise-returning function within promise-returning function

I am rather new to JavaScript and never really worked with promises before. My code works but I would like to learn if there is a better approach? I want to implement the following functionality: ...
1
vote
2answers
102 views

Racing promises and consuming them in the order of their resolution time

The ideas are When multiple async calls are made, to be able to start consuming from the first resolving one regardless in what order the promises are fired. To construct a modern emitter of async ...
8
votes
0answers
203 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 ...
2
votes
1answer
28 views

Typescript : Adding types to a function that takes in a string and returns a different promise based on the string

I have a function that takes in a string and based on the string hits different APIs to fetch images. I have solved it by writing an interface and then as the return type of the function, it returns a ...
1
vote
1answer
57 views

Get images for PDFs from URLs

I Have the below code that gets urls of PDF files, send them to a convert function and returns them as images, is there a way to make this code more readable? Is there a way to avoid functions ...
1
vote
1answer
364 views

NodeJS promise loop through all files in directory

I am trying to re-organise my mp3 collection based on its id3 meta data into folders based on the artist. I'm new to nodeJs and more importantly promises. I was hoping I could get some feedback on my ...
2
votes
2answers
67 views

Mini JavaScript thread pool with maximum number of concurrently running tasks

I wrote this mini thread pool in JavaScript that takes a maximum number of concurrently running tasks and runs them in the order it was given. I appreciate any feedback or review. Thank you. ...
3
votes
1answer
61 views

Starting with asynchronous JS and promises

I've learn to code almost alone, so I really need some ideas/advice, as it started to get really difficult to advance. Because this is mostly server side, I can't provide a running snippet, but yet it'...
1
vote
1answer
4k views

Rewriting this function to use `promises` instead of `async: false`

Using parse.com's javascript API, I would like to get a variable number or images from img tags on a page and save those images in the currently logged in user's ...
6
votes
3answers
1k 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 ...
2
votes
1answer
358 views

Send message and wait for receive while using async/await and promises the proper way

I have this working code, but sendAndReceive function looks ugly/smelly to me. Eslint complains about using await inside a loop, and using ...
4
votes
2answers
574 views

Passing data from one promise to another using then

I'm trying to get an object with ratings and titles properties: ...
3
votes
1answer
58 views

Node.js package that retrieves data from an API, formats it and sends it out via email to a distribution list

I've created a Node.js package that retrieves data from Icinga (a monitoring platform), formats it and passes it off to a class that generates some HTML and then sends it all out as an email. The ...
4
votes
1answer
1k views

Implementing Passport authentication with promises

Here is code implementing Passport authentication with a Google Strategy. It uses Mongoose to store and retrieve user data. You might need to be familiar with both of these technologies to review ...
3
votes
0answers
50 views

Go language implementation of js promise static method

I try to implement the features of the js Promise using Go. Currently, I had implemented Promise.all(), Promise.allSettled() and ...
4
votes
1answer
70 views

Correctly using promises with node-mysql

I have been trying to do a simple query and return the results with node-mysql however I had several problems. Originally I wrote it where there was no promise, but ...
-1
votes
1answer
29 views

Am I using the same Typescript variable? [closed]

I am passing a in as a parameter and want to return b. This works, however I feel like it is wrong because I shouldn't have to ...
4
votes
1answer
58 views

Input a web page with poker events, output a gcal compatible CSV file

This script takes input from poker tournament pages at pokeratlas dot com, and outputs a CSV file that I can import to Google Calendar, listing each of the tournament events, start time, location, and ...
2
votes
0answers
34 views

Handling Promise that resolves but returns a 404

This is in a node and express API. I'm trying to figure out the best way to handle Promises that resolve, but return a 404 response. I have a method which uses node-fetch to make a POST call to update ...
5
votes
2answers
1k 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 ...
3
votes
0answers
44 views

Optimisation potential when using deferred/promises and looping

I am fairly inexperienced when it comes to jQuery/JavaScript, so although the following code works, I am just looking to understand if my use of looping, deferred/promises etc could be optimised at ...
4
votes
1answer
3k views

AngularJS recursive function call with $timeout

I have created a recursive function call in AngularJS and just wonder if is there a better way to solve this problem? The code works perfectly. My code is the following: ...
5
votes
2answers
8k 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 ...
1
vote
1answer
45 views

Promise-based HTTP abstraction layer

I am currently working in a project based on a microservices architecture pattern. Services are wired up by HTTP calls. They eventually call each others for fetching or putting some data. I am ...
8
votes
2answers
523 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 ...
3
votes
1answer
191 views

A thread-safe typed Promise implementation in Java for Android

Introduction I've created a typed Promise implementation in Java for Android, borrowing ideas from this article for a JavaScript implementation, by Forbes Lindesay. To allow for "asynchronicity", my ...
1
vote
1answer
297 views

Implement jquery like functions addClass, removeClass and delay in Javascript

Assume $ is not the browser. Now have to implement $, it will take a string, which is a query, it will use the querySelector to select the element. (Reference: https://developer.mozilla.org/en-US/docs/...
9
votes
2answers
423 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 ...
0
votes
1answer
49 views

Best approach on handling function that returns either a promise or just synchronous code [closed]

I wrote some code and I'm trying to get some feedback on it. I'll try to summerize the essential only. I have a function that based on a condition returns a promise or something else: ...
-1
votes
1answer
211 views

JavaScript promise optional chaining [closed]

I've wrote a piece of code today that really make me sick about: ...
6
votes
1answer
7k 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() ...
6
votes
1answer
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 ...
3
votes
1answer
120 views

Implementing `Promise.all()`

I took a stab at implementing Promise.all(): ...
2
votes
1answer
179 views

Is returning promise form angular service bad?

What is the problem when I return a promise from angular service instead of Observable? If it's a matter of any manipulation or side-effect, that I can easily do ...
1
vote
0answers
105 views

Implementation of Promise.race [closed]

I took a stab at implementing Promise.race(): ...
5
votes
1answer
180 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 ...
2
votes
1answer
255 views

Video playback loop using promise chaining and setTimeout

Well this could seem redundant given the numerous topic about interaction between Promises and setTimeout but I can't find an answer that exactly fit my case (or that I am capable of interpreting !) ...
1
vote
1answer
248 views

ExpressJS with Promises and Ethereum

I am making a small token project with front-end website to ease the use. The architecture is Ethereum private network with ERC20 contract, PostgreSQL to associate address with alias of wallet, NodeJS ...
10
votes
1answer
207 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 ...
1
vote
1answer
50 views

Don't include root directory in HTML tree

I've written a function to create an HTML tree from JSON. ...
2
votes
1answer
231 views

Loading KML files into leaflet Javascript map

This is working code for input KML files into leaflet map ...
3
votes
2answers
82 views

Cleaner Way to Structure Asynchronous Code

The purpose of the code is to allow the user to select directories that will be crawled recursively in order to find particular files or file types to analyze en masse. The thing to bear in mind is ...
7
votes
1answer
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 ...
3
votes
2answers
97 views

Health Test App, It Returns a Score Based on the Answers Given

Here is my parent component: App.vue. I was wondering what improvements I could make to the code here. Application Description This application was built off the Vue.js framework and utilizes a ...
1
vote
0answers
26 views

Promise-based AJAX calls base class

I am more than willing to use both a Promise library and an AJAX calls one if the situation calls for it. This base class sits at the very bare bones of my system and it needs to be done right. My ...
3
votes
1answer
71 views

Throttling promise execution (API requests, etc)

I was working on a client for a remote api and realized that I needed to throttle requests at a maximum rate of 4 Hertz (4 requests per second). I wrote a simple typescript class to do it and wanted ...
1
vote
0answers
42 views

DB2 monitor using idb-connector

Monitors DB2 for changes in table data. It doesn't take any actions with the data just yet, only checks to see if new data is available every 2 seconds. ...

1
2 3 4 5 6