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
6 votes
1 answer
381 views

Exercise to fetch data from JSON files using ES6 promises

I did an exercise (self-imposed) promise fetching some data from placeholder JSON files on https://jsonplaceholder.typicode.com/. The exercise in my opinion is finished, but I can't shake the feeling ...
2 votes
1 answer
4k 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 ...
2 votes
2 answers
1k 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
1 answer
764 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
2 answers
2k 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
2 answers
572 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 ...
2 votes
3 answers
766 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. ...
6 votes
1 answer
20k views

Parallel and Sequential array looping with async/await

Are these good implementations of parallel and sequential "extension" methods, and do they accomplish what I think they do? My understanding is that the first one is parallel because the await ...
1 vote
1 answer
194 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
1 answer
104 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'...
3 votes
0 answers
613 views

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

I implemented an AsyncQueue, whose dequeue() operation returns a Promise. The ...
1 vote
2 answers
326 views

Generator function to enumerate files

I want to implement a function that enumerates all files in directory. I think the function should Return a Promise, because underlying readdir call is prefered ...
0 votes
1 answer
315 views

JavaScript / Express error handling w/ promises

So I'm wondering how to properly handle errors in JavaScript when utilizing promises. I'm currently throwing errors for everything so that I can break out of the promise - if I can't find something, ...
1 vote
1 answer
78 views

Chaining three promises in Angular.JS

I have demonstrated promise chaining where promise's p1,p2,p3 has to be resolved synchronously. The code below is using angular.js 1, and here P3 is resolved then P2 and then P1. ...
1 vote
1 answer
266 views

Async database helper function in TypeScript

I have made an async function in TypeScript that responds to Events and returns an object with methods that return a promise. I ...
4 votes
2 answers
5k views

Calling a promise recursively

I'm trying to call a promise recursively. If I get a responseData with a key error I want to call the promise again and again until I don't get it. ...
0 votes
1 answer
2k views

Exception handling and releasing of OracleDB connection

Before I start implementing several REST API service endpoints, I'd like to make sure that I'm not doing it totally wrong. ...
4 votes
1 answer
320 views

TypeScript based Promise/A+ compliant, awaitable promise class for Node.js

This is yet another Node.js Promise implementation, but this is written in TypeScript, and it strives for type safety and clarity. The full project is located here. Feel free to download it and test ...
4 votes
2 answers
6k views

Pass Async function to new Promise constructor

I'm having a hard time wrapping my head around whether or not this works or how I can even test it but.... I want to use Async/Await inside a Promise, which means, when I create a new Promise, I ...
5 votes
4 answers
940 views

Chaining async functions of a module without Promises

I know that promises are the current recommended way to go for asynchronous chaining but, every time I use promises, I don't feel as comfortable as I wish. All that "then" statements and managing ...
0 votes
1 answer
86 views

Translating words from one language to another

My program translates words from one language to another using a language Pivot and systran.io API. I used promises, callbacks and external API for the first time but I'm not sure that's the best way ...
3 votes
1 answer
4k views

Nested loop with synchronous and asynchronous behavior

The problem is as follows. I have an array of objects like so: ...
2 votes
1 answer
2k views

Processing concurrent AJAX requests

I am trying to process concurrent AJAX requests with vanilla JavaScript. Below is the sample code I've been working with ...
3 votes
0 answers
50 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 ...
5 votes
2 answers
252 views

Asynchronous JavaScript to fetch remote JSON data with promises and generators

I am trying to figure out how to do async calls using promises and generators (without 3rd party libraries). Most of the examples I found on the Internet are either incomplete or confusing (at least ...
2 votes
3 answers
90 views

Fetching AJAX results from three endpoints, with error handling

I have a requirement in which I need to get data by making AJAX calls. First search for data in endPoint1, if not found then in ...
1 vote
2 answers
3k views

Iterate array with delay in between using promise

I would like to write a nodejs IP driver for my AVR. In order to turn on my AVR and switch it to channel '321' i have to send key presses. A key press can be seen as a 'press key' and 'release key' ...
2 votes
1 answer
107 views

Session generator/checker utility for a server

I wrote a utility for generating and saving sessions in a MongoDB database as well as checking the session to make sure it's valid. I'm a beginner when it comes to promises and I have a feeling that ...
3 votes
1 answer
308 views

RSVP.hash replacement using ES6 Promise

We have a pretty big code base that made use of RSVP which we are moving to node 4.3.2+. The only RSVP feature we use frequently that's not in the native js Promise api is the hash() function. I ...
0 votes
1 answer
1k views

Return a Promise for a JSON POST

Given this method, we don't know which syntax is the more appropriate. ...
3 votes
2 answers
6k views

Javascript progress bar in succession

In the below code snippet, on click of a button, progress bars are added one by one. The bar shows up for 3 seconds. If you continuously click on the button, it will keep adding progress bars. The ...
5 votes
2 answers
985 views

Non-polling implementation of std::when_any()

The following — I claim — is a implementation of when_any from the C++ Concurrency TS, except without all the baggage around ...
1 vote
2 answers
192 views

Chaining promises into a callback

I wrote a AWS lambda function which buys €X worth of some currency on an exchange. For this I first have to find out the current price (getAskPrice), then calculate ...
2 votes
1 answer
339 views

Checking a DB table before doing an insert using AWS Lambda

Pretty new to AWS Lambda and Javascript, and particularly Promises. Simple check db table before insert. It all seems to be working - I'm just wondering if there was a neater way of doing any of ...
2 votes
1 answer
1k views

code duplication in conditional Promise

I am writing a function in Typescript that involves checking a condition, doing some extra processing if the condition is satisfied, and then doing the bulk of the job. Here's the catch: the extra ...
1 vote
0 answers
328 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 ...
3 votes
1 answer
2k views

Angular 2 service to upload a batch job and poll for results

I have to write a web interface for one of my homebrew projects. Since I'm not familiar with HTML and CSS I've decided to take heavy duty framework such as Angular 2. This is my first experiment - I'm ...
3 votes
1 answer
4k views

Fetching data from a MySQL database using Promise

I have written JavaScript code for fetching data from a MySQL database. I have used connection pooling and Promise API. ...
1 vote
1 answer
290 views

Fetching and shortening URLs with API calls using Promises

I have a node module that accesses the News API to fetch news articles and runs each article's URL through Google's URL shortener. It also has a caching mechanism implemented. This was previously ...
3 votes
2 answers
97 views

Deleting rooms using nested promises

I have a piece of code that has to deal with some nested promises and shared variables between them. This code is complicated by itself and because of promises syntax is even more difficult to read ...
1 vote
1 answer
1k views

express-validator and promise chains

Is this the correct way of chaining promises when it comes to express-validator? I am using express node and this is the endpoint for a get request Something about it seems a bit messy, but I can't ...
4 votes
1 answer
639 views

Handling login using promises

We've got this node.js code which is called by an Express route: ...
1 vote
1 answer
59 views

Asynchronous task on every element of an array

Here is some synchronous code: ...
2 votes
1 answer
891 views

Basic web scrape project written in NodeJS

Here is a short program web scraping program written in Node.js. I'm just getting to grips with node and this is the first thing I've written with it. I'm liking it so far though I guess I'm kinda ...
2 votes
0 answers
836 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 ...
0 votes
1 answer
129 views

Ensure every element in array passes asynchronous test

I've written a function which ensures all objects in the items array belong to the user. This involves a database check, which ...
5 votes
2 answers
1k views

Using JavaScript promises to display weather and location information

This is the first time I'm trying to use promises in JavaScript so I'm not sure if I have done it correctly, but it seems to work. The problem is that I have ended up with a "nested ...
1 vote
1 answer
190 views

Parallel class for javascript promises

I created a class to run a certain number of tasks in parallel in the browser. The constructor takes an array of inputs, a function that takes a single input and returns a promise, and a count of the ...
1 vote
0 answers
559 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 ...
3 votes
0 answers
70 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 ...