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.

34 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4 votes
0 answers
254 views

Mongoose and Hapi/Express promise handling in controllers

I'm switching my code to promises - mostly as delivered by Mongoose. I use Hapi though I think something similar would apply to Express. In my models/services I perform queries such as: ...
cyberwombat's user avatar
3 votes
0 answers
56 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
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
3 votes
0 answers
569 views

Blocking Promise-driven queues with ECMAScript's async/await and generators

I implemented an AsyncQueue, whose dequeue() operation returns a Promise. The ...
ComFreek's user avatar
  • 751
3 votes
0 answers
47 views

Showing a Wikipedia article's changes as Git commits

I created a small-ish NodeJS script which takes as argument the name of a Wikipedia article (and optionally a Wikipedia edition, "en" is default) and creates a Git repository with each change made to ...
Bruno Pérel's user avatar
3 votes
0 answers
69 views

A function that debits a virtual wallet and calls an API to disburse to a real account

I am trying to determine if there is a better way to handle reversals for this function. This is how it works: A user inputs in amount, bank, and account number this would be used to debit his ...
temiloluwa adesina's user avatar
3 votes
0 answers
283 views

AngularJs: Preventing multiple $q.get() per url

I've wrote a pretty useful method to prevent multiple requests per single get url. There is a well known pattern - to store promise and return it for each next ...
Kindzoku's user avatar
  • 218
3 votes
0 answers
243 views

Wrapping a node.js module using elasticsearch

I need to use elasticsearch in my node.js project, whose API looks like the following: ...
user490895's user avatar
3 votes
0 answers
132 views

Q.js worker pool

I'm building a program to scrape data about hockey games in order to compile statistics. One of the run modes will process all of the games in a single season (1230). Processing a single game consists ...
pgraham's user avatar
  • 400
3 votes
1 answer
559 views

Recursion into git diff tree using nodegit

I'm using nodegit to develop the backend for a nodejs app that uses a mix of mongodb and git for persistence. The app has to version documents and be able to present diffs between versions, thus the ...
jotadepicas's user avatar
2 votes
0 answers
160 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
2 votes
0 answers
443 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
2 votes
0 answers
783 views

Promise-based unit tests using Pub/Sub

I've recently been learning and adopting Promises, async/await, and unit testing for my JavaScript server project. I just finished a unit test for some pubsub code that was more convoluted than ...
odigity's user avatar
  • 121
2 votes
0 answers
176 views

Chaining multiple async calls and data manipulation within promises

Is there a better way to do this (clean, efficient, good practices)? ...
Cybrix's user avatar
  • 121
2 votes
0 answers
62 views

Cache for slow API

I work with an API which answers really slowly. I created a module which constantly asks the API and update some cached value. The code is degraded for study purposes: ...
kharandziuk's user avatar
2 votes
0 answers
2k views

Flux & async communication with websockets

I want to arrange async server-client communication with websockets and vanilla flux architecture. There is an excellent article about "Async Server-Side Communication with the Flux Architecture". I ...
VB_'s user avatar
  • 237
2 votes
0 answers
509 views

NodeJS authentication function rewrite with promises

I will post both of the modules, some of the code in them may be "irrelevant" for the main concern here, which is Security.prototype.authenticate(). Nevertheless, comments are welcome about all of the ...
Markus Pint's user avatar
2 votes
0 answers
67 views

Rewriting authentication controller using promises

I am in the process of refactoring some complex code that uses callbacks to instead use promises. I am trying to figure out if my proposed approaches make sense. ...
Kevin's user avatar
  • 121
1 vote
0 answers
112 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
  • 33
1 vote
0 answers
38 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
0 answers
43 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
  • 245
1 vote
0 answers
51 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. ...
Cody Pace's user avatar
  • 193
1 vote
0 answers
38 views

Using promises to zoom to a project, then to a task or comment

How to beautify this part of code? (I mean usage of promise in promise) I really have no clue how this could've look like. ...
degath's user avatar
  • 107
1 vote
0 answers
83 views

Webscraping with Cheerio

I would like to get a code review about my Cheerio code. I'm trying to scrape a dutch book store with Cheerio. The web scraping takes up between 1,5 and 3,5 seconds per book. I would like the ...
Elvira 's user avatar
  • 111
1 vote
0 answers
54 views

Custom indexeddb modules while trying to maintain the functional paradigm as much as possible

I'm a Web Development student, and I just started learning indexeddb a little while ago. At present my teacher hasn't taught us Promises, and I'm not really sure he plans to. So, I took the initiative ...
Ucenna's user avatar
  • 141
1 vote
0 answers
317 views

Exporting functions that manipulate mongoose models

I have the following code in a file called database.js which will handle all the database operations for my small application. For some background, this application ...
omgimanerd's user avatar
  • 1,157
1 vote
0 answers
558 views

Simple Promise implementation

I am trying to hack together a simple promise implementation. Is the following approach of maintaining a single async call and linking nested promises dynamically using their ...
52d6c6af's user avatar
  • 672
1 vote
0 answers
74 views

NodeJS controllers for a bus and a user

I'm writing my server and now I'm creating a controller for each route so I could use the same controller in different apis rather than rewrite the same code over and over. Below is my code example of ...
motchezz's user avatar
1 vote
0 answers
340 views

Queue that permits at most X simultaneous operations

I ran into this once (permits=N) and then again today (permits =1) where I only want 1 to N operations running simultaneously. One example comes from firing into a state machine (the permit=1 example)...
Dean Hiller's user avatar
1 vote
0 answers
277 views

Weather-App for terminal done with node.js, OpenWeatherMap and ES6 promises

I've started to learn node.js a few weeks ago. This weekend I've made a tiny app for to recap what I've learned so far. It uses OpenWeatherMap as a data-source. The user calls the main file (...
michael.zech's user avatar
  • 3,990
1 vote
0 answers
436 views

List all files matched by glob within JSON file

Based on a set of globs contained in a custom field within a package.json file, I'm trying to get a list of all the files that the glob matches. In my continual quest to get more familiar with ...
1252748's user avatar
  • 187
1 vote
0 answers
209 views

JavaScript making http(s) request: requiring modules within a function

This JavaScript code is being used as part of a reporting tool that makes http(s) GET requests to an API, bundles responses and uploads them as files to an AWS S3 bucket. It's a script that runs ...
snakeandrooster's user avatar
0 votes
0 answers
63 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
0 votes
0 answers
184 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