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
2
votes
1answer
40 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
16 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
67 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
96 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
76 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
40 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
32 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
53 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
30 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
77 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
52 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
192 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
39 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 ...
3
votes
1answer
368 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
110 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
40 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
53 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
0answers
211 views

Extending native JavaScript Promise with cancellation support

I'm playing with Promise Extensions for JavaScript (prex) library. I want to extend the standard Promise class with cancellation support, similar to how it is implemented in Bluebird (i.e., with an ...
6
votes
1answer
80 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
18 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
1answer
51 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
1answer
96 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, ...
5
votes
2answers
117 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
1answer
28 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 ...
3
votes
1answer
159 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 ...
7
votes
2answers
191 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 ...
0
votes
1answer
412 views

Promise-based fixed delay poller with timeout

I have the following functions for polling some function periodically with a timeout ...
0
votes
1answer
34 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 ...
7
votes
2answers
212 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 ...
-2
votes
1answer
33 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
1answer
188 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
2answers
77 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
1answer
79 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, ...
4
votes
1answer
76 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
1answer
2k views

Script to load controllers dynamically for AngularJS

I would like to hear your thoughts, idea's or feedback on the following code. Ive added to code to github. https://github.com/redbullzuiper/angularjs-dynamic-controllers Usually when you attach a ...
1
vote
0answers
50 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 ...
1
vote
1answer
905 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 ...
2
votes
2answers
745 views

Promise.all, but with enforced limit on concurrent promises

I'm trying to implement parallelLimit() to limit the number of parallel tasks that can be performed at any time. Personally, I'm using this function for limiting ...
4
votes
1answer
151 views

Read files from a directory using Promises

Using javascript functions and the old way of doing things I wrote a piece of code to copy the first file in a directory to a file Test. ...
3
votes
2answers
341 views

Using await to break long-running processes

I have a Node.js app / Web API that runs on an Azure app service with a single CPU. One of the functions needs to run for a long time, perhaps tens of seconds, while the server should continue to ...
1
vote
2answers
288 views

Asynchronous Queue

implemented a basic Asynchronous Queue so, that I can do await queue.push(item); const item = await queue.pop(); basically I'm trying to convert a synchronous ...
1
vote
1answer
113 views

Monkey-patching Jasmine's it() function to log errors

The introduction of async native support in Jasmine doesn't log the errors (i.e., specific line number where the error occurs) to the console. So, to get around this behavior and to make the errors ...
1
vote
1answer
51 views

Asynchronous Stack

implemented a basic asynchronous stack so, that I can do. await stack.push(item); const item = await stack.pop(); basically I'm registering listeners when ever i'...
2
votes
3answers
238 views

Fetching user details, posts, and comments using promises in ExpressJS

I'm creating an API service in NodeJS using Express (version 4) Framework. Created an MVC architecture for the same (no views, only model, and controller as this is an API). Also, there are routes. ...
5
votes
1answer
607 views

Promise implementation in Python

Recently I made an basic port of the JavaScript Promise construct to Python. Here's the basic code: ...
3
votes
0answers
351 views

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

I implemented an AsyncQueue, whose dequeue() operation returns a Promise. The ...
0
votes
1answer
209 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 ...
2
votes
1answer
238 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 !) ...