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.

Filter by
Sorted by
Tagged with
4 votes
2 answers
897 views

Bluebird: promisify xhr request

I use bluebird promises. I want to promisify my requests from communication layer: Utils.js ...
Nickole Abs's user avatar
2 votes
1 answer
41 views

Async db repository

This is a simple repository where I want to save all the invoices of some queried users. I wanted this module to only expose a simple saveInvoices method and return ...
teebot's user avatar
  • 123
0 votes
1 answer
8k views

Access resolve function outside of a JavaScript Promise

I have an object that needs to have a single point of initialization, and other callers need to wait until the initialization is complete before continuing. I have done this with jQuery, and it feels ...
Joseph Gabriel's user avatar
4 votes
2 answers
3k views

Promises with NodeJS and BlueBird

I'm using bluebird for promises in my Node/Express application and wrote an API call in which the user passes in a JSON Web Token that contains their user ...
Thomas's user avatar
  • 143
2 votes
3 answers
179 views

Save handler without a nested "deferred antipattern"

I have an application in which a user makes a change, and when they click Save they will be prompted to confirm, and the appropriate REST call will be made if they agree. The intial call to ...
The DIMM Reaper'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
1 vote
1 answer
470 views

File existence promise

I hate to have to write a custom exists promise every time I need to know if a file exists, so I came up with this. Thoughts? ...
ThomasReggi's user avatar
5 votes
1 answer
167 views

Deleting a section of a website using Ajax

I am currently writing a decent amount of ajax to help me delete a section of a website. It's already becoming a pretty big piece of code, I wondered if it were possible to compact a section of my ...
099's user avatar
  • 337
1 vote
1 answer
106 views

Taking and saving pictures using promises

I have the following 4 functions that work, however, I am sure that utilising promises will improve my code. I just find them so confusing. ...
Taylorsuk's user avatar
  • 261
6 votes
1 answer
3k views

Asynchronous iterator for AngularJS

I wrote this as a convenient way to batch together multiple, repetitive AJAX calls. I was working in angular at the time, so I use the $q service, but I'm sure it ...
Chris's user avatar
  • 163
2 votes
1 answer
2k views

Resolving promises on resolver using ui-router

We're rewriting some parts of our application. We're trying to avoid the promise anti-pattern and do things properly, but I'm not certain that we did so. More precisely, we are rewriting the resolver ...
avcajaraville's user avatar
2 votes
1 answer
4k views

Angular Broadcast Asynchronous Events

Okay I have the following use case: Module A broadcasts an event. Module B listens to that event. Maybe also ...
jantimon's user avatar
  • 121
3 votes
1 answer
119 views

Flow of Angular Promises

I recently put in a submission for a small coding challenge using Angular. The challenge was to get a token and array of values using a GET request then make another GET request passing the token and ...
br3w5's user avatar
  • 255
4 votes
1 answer
27k views

Use Promise to wait until DOM element exists

I need to create a JavaScript Promise that will not resolve until a specific HTML element is loaded on the page. I don't have any way of knowing when this element will be loaded, other than to simply ...
Joseph Gabriel's user avatar
6 votes
1 answer
1k views

Detecting gyroscope data using promises

In a plugin that I am currently authoring, I am using a function to check whether the device provides gyroscopic data. Although intuitively this can be easily resolved by checking the value of ...
Terry's user avatar
  • 185
1 vote
1 answer
126 views

Logging out using nested promises

Is it OK to do that ? for example, I have my log out service ...
Non's user avatar
  • 183
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
2 votes
1 answer
132 views

Validate IP address and create a registration attempt

I'm a C++/Python developer attempting to learn JavaScript, but I'm struggling to write clean code. I've read that async.waterfall and Promises are two ways to flatten the code a bit, but my ...
Cryo's user avatar
  • 123
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
1 vote
1 answer
4k views

Rewriting this function to use `promises` instead of `async: false`

Using parse.com's javascript API, I would like to get a variable number or images from img tags on a page and save those images in the currently logged in user's ...
Wesley Smith's user avatar
4 votes
1 answer
62 views

Input a web page with poker events, output a gcal compatible CSV file

This script takes input from poker tournament pages at pokeratlas dot com, and outputs a CSV file that I can import to Google Calendar, listing each of the tournament events, start time, location, and ...
Eric Blade's user avatar
5 votes
1 answer
13k views

Java 8 CompletableFuture - fan out implementation

I was wondering what is the best way to implement a fan out type of functionality with Java 8 Completable future. I recently rewrote a function that had a bunch of old ...
Feras's user avatar
  • 213
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
1 answer
97 views

Fetching ALL data set from API iterating via response data

Does this make sense? How would you achieve the same thing, with cleaner code? ...
ThomasReggi's user avatar
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
6 votes
2 answers
10k views

Unit testing a click event with asynchronous content

I'm writing unit tests for a web application that has quite a lot of UI interactions. I would like some feedback regarding on how to handle click events with asynchronous code. My goal here is to ...
Johan's user avatar
  • 631
5 votes
1 answer
1k views

Using $q in Angular JS to pass navigator geo JSON from factory to controller

This code is used to get the users location and deliver it as a resource to the controller. The aim is to have this data shared across multiple controllers in the application. So far this does deliver ...
zia grosvenor's user avatar
3 votes
1 answer
88 views

Checking for JSON or YAML file with promises

I'm using bluebird promises. I'm converting fs.exists to existsAsync (here's how) and ...
ThomasReggi's user avatar
3 votes
1 answer
374 views

Using the $q service in AngularJS to handle promises

I have a service which needs to store some settings data in a DB and at the same time maintain a reference to that in the user'slocalStorage (we want two users ...
BadgerBadgerBadgerBadger's user avatar
6 votes
1 answer
4k views

NodeJS and Express with Promises

I'm relatively new to NodeJS and Express, and I've recently run into the pyramid of Doom while doing stuff that requires multiple steps. I've found that promises are very promising indeed. But I ...
jhenriquez's user avatar
11 votes
2 answers
2k views

Implementing JQuery style 'deferred' and 'promise' in C#

I like the pattern of the jQuery Deferred object. I like how you can call Resolve any number of times, but the listening objects will only be notified once. I also ...
Andrew Shepherd's user avatar
0 votes
1 answer
197 views

Make sequential fadeIn() promises more manageable

I've two versions of promise code. The page is a simple one - an unordered list with a few items. I am trying to make the items show up (fadeIn) one-after-another ...
deostroll's user avatar
  • 175
5 votes
1 answer
133 views

Reading the contents at three URLs using Promises

I'm learning promises and now I'm trying to figure out if something in this code can be improved. This code is expected 3 urls and then async parallel calls should be done. When all requests are ...
Max Grigoriev's user avatar
7 votes
1 answer
2k views

Using a Wrapper Promise

I wrote some code for an application that uses the following pattern: ...
aebabis's user avatar
  • 123
2 votes
1 answer
222 views

Node.js API route for POSTing a resource. Getting rid of callback pyramid

I'm writing an API for simple GET and POST routes. The app is a shared to-do-list. Users and lists are stored separately. A list can belong to many users, and a user can have many lists. ...
Victor Sand's user avatar
9 votes
1 answer
2k views

Node module using promises and the revealing module pattern

Can someone give me some feedback on this pattern? I am writing a node.js module that connects to a remote API, caches JSON, returns it as output. I have a cli wrapper script that uses the module, ...
Sammers's user avatar
  • 93
2 votes
1 answer
226 views

Pyramidal promises

I have a situation in my Node (express) controller where I need to check whether a particular language has a parent language, if it does, I need to do a new DB (SQL) call to retrieve the parent ...
Joseph's user avatar
  • 165
22 votes
1 answer
15k views

Simple Async Google Maps initializer with AngularJS

Here is a simple reusable AngularJS factory I came up with to initialize Google Maps Asynchronously, which somehow does not seem ...
Dmitri Zaitsev's user avatar
12 votes
2 answers
2k views

Simple AngularJS controller for REST API

We record software builds from our build machine into a database and for practice purposes I'm building a little web dashboard for it. The API is REST (WebApi) and provides access to query for ...
ChrisWue's user avatar
  • 20.1k
3 votes
2 answers
318 views

Promise.jsm demo of Promise.all and Promise.defer

I created this demo example for MDN documentation to show how to use Promise.all and Promise.defer in user created promise. I ...
Noitidart's user avatar
  • 261
3 votes
1 answer
413 views

Two dialog boxes using Deferreds?

I've two similar functions and I want to use one generic function with two params, dialog and buttons. How do I do it? My ...
Viktor's user avatar
  • 181
1 vote
1 answer
4k views

Is this a reasonable way to implement promises in node.js?

I'm using passport to setup login in an express site. The site is just a playground for me to learn. The code inside login was exhibiting the arrow anti pattern so I decided it was time to learn to ...
Paul D'Ambra's user avatar
12 votes
1 answer
461 views

Pledge: Promise-like entities design goals experiment

Background I was writing a promises/a+ implementation, just for fun. About halfway through I decided it wasn't that fun after all, so I decided to do something a little different. Thinking of ...
Dagg's user avatar
  • 4,531
10 votes
2 answers
15k views

Caching/memoizing promise results

I'm wondering what the best approach might be. One approach is to chain cachedPromise and "regular", thus, if cachedPromise ...
shabunc's user avatar
  • 233
2 votes
1 answer
365 views

Testing Promises vs Lock performance

I'm not sure if my lock usage is correct and safe. I wanted to know what will be best approach to deal with situation when one thread have to wait for being initialized by another so I written this ...
czajah's user avatar
  • 121
11 votes
2 answers
4k views

NodeJS broker between MongoDB and RabbitMQ

I wrote a small program that aims to take some data from the MongoDB database and put them in the RabbitMQ queue. I tried to use only promise style but I am a beginner in JavaScript. Could you please ...
Julio's user avatar
  • 113
2 votes
2 answers
864 views

Cleaning up nested promises in Cloud function

I am writing the Cloud function for Parse whose purpose is to update my database with a provided array of data objects. The main problem are the nested promises, which doesn't look right. Any help ...
Dmitri Zaitsev's user avatar
2 votes
1 answer
465 views

Promise-driven animation

Inspired by this question on Stack Overflow, I've attempted to code such animation, mostly to get some more practice with async, promises and Q.js: (Live demo) ...
Kos's user avatar
  • 213
1 vote
2 answers
918 views

Promises and chained calls

I've realized JS callback hell and I started looking into Promises libraries. After reading some articles I decided to start with BluebirdJS. I didn't realise how to properly use them yet, because ...
user0103's user avatar
  • 176
5 votes
1 answer
679 views

AngularFire Tic Tac Toe Game

I am building a Tic Tac Toe game with AngularJS and making it online playable with AngularFire. The Tic Tac Toe logic is all there so this question concerns Angularfire a little bit more. I want to ...
user3267289's user avatar