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
1 vote
0 answers
135 views

Implementation of Promise.race [closed]

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

Loading KML files into leaflet Javascript map

This is working code for input KML files into leaflet map ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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. ...
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 ...
1 vote
1 answer
24 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 ...
2 votes
2 answers
695 views

Web-App for to determine gender, age, emotions of a person (shown on an image)

I have made an app using Microsoft's Face API: Face API JavaScript Quick Start It shall analyze an image, showing a person's portrait, concerning the gender of the person, her/his age and emotions. ...
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 ...
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 ...
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. ...
0 votes
1 answer
47 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
1 answer
50 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 ...
3 votes
1 answer
415 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
0 answers
61 views

Vue.js Computed Property Filtering [closed]

I have a Vue.js computed property as follows. ...
1 vote
2 answers
453 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 ...
6 votes
1 answer
388 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. ...
2 votes
1 answer
862 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,...
2 votes
1 answer
2k 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. ...
1 vote
1 answer
67 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
1 answer
1k views

React component to list TV shows from a JSON result

I'm trying to rewrite my old project in Reactjs. As I am a beginner and this is my first app, I need some assistance in understanding what is the best way to do this in the React way and how I can ...
3 votes
3 answers
131 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
1 answer
153 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
1 answer
64 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 ...
1 vote
1 answer
60 views

DRYing out my action creators

I've created a private function called _successResponse to handle successful responses from my promise. The challenge was passing the dispatch function to the <...
2 votes
1 answer
66 views

Javascript class to geocode Dutch addresses

I am relatively new to javascript ES6, the code I've written is working fine. However I am curious if this would be the best approach. I am trying to write a reusable module that I can use in multiple ...
1 vote
1 answer
112 views

On form submission, upload an image if there is one, then start update event

What is the expected behavior? If there is a file in the state (file != null), then startUploadImage(file) should be executed, ...
7 votes
2 answers
271 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 ...
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, ...
5 votes
2 answers
851 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 ...
1 vote
1 answer
33 views

Retrying a request using 'request' library without extra modules

I am using the request module and wanted to implement some retries for robustness. It seems excessive to use a whole new or extra module just to do a retries so I've put together the following as an ...
5 votes
1 answer
909 views

Promise implementation in Python

Recently I made an basic port of the JavaScript Promise construct to Python. Here's the basic code: ...
1 vote
1 answer
120 views

Making JSON requests to fetch relationships asynchronously

I would like to refactor the fetchRelationships function to use async await. I am not sure what the best way is to do it as this code contains nested .then at ...
3 votes
1 answer
484 views

Enforce request completion order using Multiple Promise Chaining

The main entry point is the SyncmyCompany() function. I have a interesting scenario where I'm syncing data from a Company to a destination system. In this case ...
0 votes
1 answer
2k views

Promise-based fixed delay poller with timeout

I have the following functions for polling some function periodically with a timeout ...
1 vote
1 answer
1k views

Read files from a directory using Promises V2

Follow up to Read files from a directory using Promises Removed exists() and replaced with stat() so I can check if the file is ...
0 votes
1 answer
41 views

Accumulate ids to make a single ajax request

I have multiple places where I need to make ajax requests to fetch the items corresponding to some ids. However, I only want to make a single request by accumulating these ids and debouncing the ...
-2 votes
1 answer
40 views

Node.JS Promises and Logging in [closed]

I'm learning about Node.js and also Express.js, and attempting to create a forum like website in the process of such, I currently want the user to be able to register an account, and then log into it ...
4 votes
1 answer
484 views

Local weather app made with Typescript

I would like feedback on my Local weather app. This site simply gets the local weather. I refactored it from jQuery to Typescript to try to learn more about Typescript. Here is a demo: https://...
2 votes
2 answers
91 views

Processing a list of pairs of items using promises and functional programming

I posted an answer on StackOverflow which I believed to be adherent to the principles of Functional Programming. However, I was told by the original asker that it was not 'functional' as my function ...
3 votes
1 answer
171 views

Basic ethereum transfer codes using web3js, ganache, node

I want to get advice about functional programming using javascript promise. Please look through my code and give me a feedback how I could make code better. As I begin to use promise a few days ago, ...