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
0 votes
1 answer
55 views

Handling pure in browser HTTP request in Service Worker fetch event

I was suggested by @Bergi on StackOverflow that Async Promise constructors are any pattern. The argument behind this is that async Promise swallows the errors. In my case, I have try..catch so I'm not ...
jcubic's user avatar
  • 238
0 votes
0 answers
280 views

Promise queue Typescript

As an exercise, I wrote a promise queue in Typescript. The point of it is to parallelise a maximum number of promises, and not just Promise.all() to batter the ...
Lewis Farnworth's user avatar
3 votes
2 answers
105 views

Idempotent JavaScript script loader

I wrote an idempotent script loader (for the browser), where the same script won't be loaded more than once. scriptLoader.js: ...
lonix's user avatar
  • 143
1 vote
0 answers
198 views

Promise in an Express app to send OTP verification e-mail

In this code I'm using nodemailer for sending otp email from my gmail account. I have also used ejs for creating html templates for emails. This code works perfectly, but I am a bit concerned about ...
Bhaskar's user avatar
  • 133
0 votes
0 answers
236 views

Promise to save an image to Firebase and obtain the resulting URL

I'm trying to write a promise that will return me the image URL value that I'm getting from firebase once It is saved to the firebase storage. After some time I wrote the following code and it is ...
Zoran Janjic's user avatar
2 votes
1 answer
96 views

Basic node login routes for authentication system

I am building a basic authentication system with a node backend and wonder whether I am using the try-catch block excessively. I have this example controller: ...
user8758206's user avatar
2 votes
0 answers
244 views

JavaScript proxy for better stack traces from external libraries

I've been using the excellent pg-promise library for a few years now, but my primary irk with it is that the stack traces are sometimes unhelpful. For example, the following test will fail (currently ...
BrDaHa's user avatar
  • 133
1 vote
1 answer
355 views

React Native login, sign up and sign out using Firebase project

I have built a basic app which uses firebase for authentication. The app is pretty simple. Sign up the user to firebase using email and password. Sign in the user Sign out the user Also, I have ...
Eduards's user avatar
  • 225
1 vote
1 answer
69 views

Managing file names in a file

The scenario here is to get a filename from the console and create it if it does not exist. I have two main questions; Is the way I used promises the best way? is there a better way? Here is my code;...
Safnas's user avatar
  • 59
2 votes
1 answer
250 views

Check RSS feed and post to Discord

I'm new to using JS for anything other than DOM manipulation, so I'm not sure if the following code is taking full advantage of the Async concept in JS. This is an example of a function I'm writing in ...
RaVeN's user avatar
  • 23
2 votes
2 answers
70 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. ...
Bhaskar's user avatar
  • 133
4 votes
1 answer
1k 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. ...
slepic's user avatar
  • 5,367
1 vote
0 answers
39 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: ...
btzs's user avatar
  • 111
1 vote
2 answers
401 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 ...
Redu's user avatar
  • 856
2 votes
1 answer
38 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 ...
rakshith's user avatar
1 vote
1 answer
59 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 ...
user3378165's user avatar
1 vote
1 answer
2k 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 ...
James's user avatar
  • 197
2 votes
2 answers
135 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. ...
Node.JS's user avatar
  • 389
3 votes
1 answer
67 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'...
Minsky's user avatar
  • 239
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
2 votes
1 answer
2k 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 ...
heltonbiker's user avatar
4 votes
2 answers
634 views

Passing data from one promise to another using then

I'm trying to get an object with ratings and titles properties: ...
MauricioRobayo's user avatar
3 votes
1 answer
64 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 ...
Arran Scott's user avatar
3 votes
0 answers
58 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 ...
Lin Du's user avatar
  • 159
-1 votes
1 answer
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 ...
user10076130's user avatar
2 votes
0 answers
561 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 ...
FlameDra's user avatar
  • 151
3 votes
0 answers
49 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 ...
ccdavies's user avatar
  • 181
4 votes
1 answer
249 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 ...
Ian's user avatar
  • 141
1 vote
1 answer
50 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 ...
VRoxa's user avatar
  • 146
3 votes
1 answer
356 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 ...
Codifier's user avatar
  • 178
1 vote
1 answer
845 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/...
Umang Gupta's user avatar
10 votes
2 answers
489 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.8k
0 votes
1 answer
92 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: ...
Ionut Necula's user avatar
-1 votes
1 answer
479 views

JavaScript promise optional chaining [closed]

I've wrote a piece of code today that really make me sick about: ...
Tiziano's user avatar
  • 111
14 votes
2 answers
36k 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
1 vote
0 answers
135 views

Implementation of Promise.race [closed]

I took a stab at implementing Promise.race(): ...
Tobi Alafin's user avatar
  • 1,806
4 votes
1 answer
164 views

Implementing `Promise.all()`

I took a stab at implementing Promise.all(): ...
Tobi Alafin's user avatar
  • 1,806
5 votes
1 answer
208 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
2 votes
1 answer
402 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 ...
Siraj M's user avatar
  • 115
1 vote
1 answer
59 views

Don't include root directory in HTML tree

I've written a function to create an HTML tree from JSON. ...
oldboy's user avatar
  • 151
3 votes
2 answers
86 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 ...
oldboy's user avatar
  • 151
3 votes
2 answers
103 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 ...
Harrison Greeves's user avatar
2 votes
1 answer
486 views

Loading KML files into leaflet Javascript map

This is working code for input KML files into leaflet map ...
Geographos's user avatar
1 vote
0 answers
64 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 ...
coolpasta's user avatar
  • 235
10 votes
1 answer
273 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
3 votes
1 answer
94 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 ...
erikdstock's user avatar
4 votes
2 answers
156 views

Static site generator using JavaScript Promises

I have created a small static site generator (for learning purposes) in Javascript ES6, using Promises, but I am not certain of how to use them well. The code below works fine, but I wonder if i can't ...
Thomas's user avatar
  • 43
3 votes
1 answer
1k views

TamperMonkey Script to replace the YouTube favicon with the channel logo

I felt that having a plain red favicon for every youtube tab is a little boring. So, I wrote a TamperMonkey Script with the new ES6 promises that replaces the favicon with the channel's logo. Link to ...
Kartik Soneji's user avatar
3 votes
1 answer
6k views

Retry a Promise resolution N times, with a delay between the attempts

I want some JavaScript code to take 3 things as parameters: A function returning a Promise. The maximum number of attempts. The delay between each attempt. What I ended up doing is using a ...
ttous's user avatar
  • 133
0 votes
1 answer
62 views

Making two sequential asynchronous requests using promises

The following code is making two asynchronous requests to obtain the desired data. The second request needs to access the data from the first request, hence I need to nest it. I know that it is better ...
Emanuele Paolini's user avatar

1
2 3 4 5 6