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
3answers
574 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
17 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
537 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
50 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 ...
3
votes
0answers
41 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 ...
-1
votes
1answer
28 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 ...
2
votes
0answers
28 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 ...
3
votes
0answers
41 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
36 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
vote
1answer
42 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 ...
3
votes
1answer
154 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
51 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/...
0
votes
0answers
27 views

Code for a function that behaves like a promise

I have come up with the following code which behaves like Promise. The interface that this provides is follows: ...
9
votes
2answers
392 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
0answers
35 views

Fetch HTTP wrapper and API

I have written a basic HTTP wrapper around the fetch. Then a API service which add some default options/parameters. the idea is ...
0
votes
1answer
42 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
58 views

JavaScript promise optional chaining [closed]

I've wrote a piece of code today that really make me sick about: ...
4
votes
1answer
929 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() ...
1
vote
0answers
73 views

Implementation of Promise.race [closed]

I took a stab at implementing Promise.race(): ...
3
votes
1answer
100 views

Implementing `Promise.all()`

I took a stab at implementing Promise.all(): ...
5
votes
1answer
98 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
83 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
1answer
50 views

Don't include root directory in HTML tree

I've written a function to create an HTML tree from JSON. ...
3
votes
2answers
79 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 ...
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 ...
2
votes
1answer
126 views

Loading KML files into leaflet Javascript map

This is working code for input KML files into leaflet map ...
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 ...
7
votes
0answers
131 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
55 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
35 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. ...
4
votes
2answers
110 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 ...
3
votes
1answer
396 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 ...
2
votes
1answer
2k 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 ...
0
votes
1answer
51 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 ...
1
vote
0answers
36 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. ...
0
votes
1answer
39 views

Handling a PUT API call to write to a database using promises

The following function is accepting PUT connection to a server API, checks authorization to write and then performs write to a database. The eslint linting tool ...
3
votes
1answer
169 views

Separating Fetch Calls and using in Promise Chain

I´m currently working on a small microservice application, which will in it´s simplest form just receive a Request from a Formular and and based on containing information perform several other Server-...
2
votes
0answers
53 views

Vue.js Computed Property Filtering [closed]

I have a Vue.js computed property as follows. ...
3
votes
1answer
35 views

JavaScript that deletes everything inside a folder on Box.com

I just finished a simple script for Node that will delete all the folders and files inside a specified folder ID through Box's API. It works by getting a list of items inside a folder, then generating ...
1
vote
2answers
161 views

Get an array of currency exchange prices based on asset

Function getMarkets Makes a call to get Cryptocurrency Exchange data based on asset (USD, USDC, USDT) It calls the endpoint 3 times to return 3 arrays which are then returned to the callee. I have ...
2
votes
1answer
267 views

Wrapping fetch(), preserve promise-based API for outer function

One of my react component's methods is using an async fetch() internally. After fetching the response from the server, it is being converted to JSON, then I perform a check on that JSON string. ...
2
votes
1answer
383 views

Execute promise tree in order of declaration

I have created a little framework for my work to manage loading and unloading plugins by using a modular tree structure that is based on Promises. I would like to be able to create the tree structure,...
1
vote
1answer
47 views

Promise for request/response with timeout

Below is a piece of code that uses a promise for sending a request to a server, and to wait for an answer. Under normal conditions the server will always respond immediately, But of course you don't ...
4
votes
1answer
873 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
3answers
113 views

Showing statistics of popular JavaScript frameworks from GitHub API

I am currently working on a simple app to check the stats of popular javascript frameworks. For this I am using the Github API to get certain data sets and have come close to finishing my project. <...
0
votes
1answer
42 views

fetch() with status code checking and re-routing

In examples for fetch() I don't see many example for status code checking. (1) I'm expecting to catch 403 unauthorised responses and push the login path to React ...
1
vote
1answer
56 views

Turning nested jQuery Promises into flat code structure using .done() and .then()

This code uses jQuery promises in combination with callbacks does the following: Saves Group UUID to server using storeGroupOnServer() Creates a DOM element for ...
5
votes
2answers
674 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 ...
6
votes
1answer
262 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. ...
1
vote
1answer
19 views

Saving a submitted Mongoose model, possibly with an uploaded image

I have some code which saves a mongoose model from the submitted form data. However the user might also upload an image along with the form, which needs to be saved on the server (moved from the ...

1
2 3 4 5 6