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
900 views

Bluebird: promisify xhr request

I use bluebird promises. I want to promisify my requests from communication layer: Utils.js ...
2 votes
1 answer
42 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 ...
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 ...
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 ...
2 votes
3 answers
181 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 ...
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 ...
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 ...
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 ...
1 vote
1 answer
472 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? ...
5 votes
1 answer
168 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 ...
3 votes
1 answer
122 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 ...
3 votes
2 answers
321 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 ...
1 vote
1 answer
112 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. ...
5 votes
1 answer
14k 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 ...
4 votes
0 answers
256 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: ...
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 ...
3 votes
1 answer
418 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 ...
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 ...
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 ...
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 ...
1 vote
1 answer
127 views

Logging out using nested promises

Is it OK to do that ? for example, I have my log out service ...
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 ...
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 ...
1 vote
1 answer
101 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? ...
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 ...
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. ...
2 votes
1 answer
466 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) ...
3 votes
1 answer
383 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 ...
3 votes
1 answer
119 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 ...
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 ...
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 ...
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 ...
0 votes
1 answer
202 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 ...
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 ...
7 votes
1 answer
2k views

Using a Wrapper Promise

I wrote some code for an application that uses the following pattern: ...
12 votes
1 answer
490 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 ...
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 ...
2 votes
1 answer
94 views

My yld NPM - callbacks/promises alternative

I'd like feedback on my callbacks/promises alternative, please. The yld repository ...
2 votes
1 answer
377 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 ...
1 vote
2 answers
919 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 ...
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 ...
5 votes
1 answer
691 views

Angular promise in service

I'm new with Angular promise and I would like to know how to improve my code. I have a service which preload media or data by calling an API. The media API return an array of urls to preload. ...
2 votes
1 answer
267 views

Thoughts on this conversion of code from Step.js to Q promise library?

I have some code that I'd written using this pattern with Step.js. In this case, talking to MongoDB in Node: ...
6 votes
1 answer
260 views

Structuring functions receiving and returning promises?

I keep running into the same pattern with code using promises in javascript. When writing a function which takes a promise and returns a promise, obviously I want to reject the promise I'm returning ...
3 votes
1 answer
1k views

Limiting Q promise concurrency in JavaScript

I wrote a helper to limit Q promise concurrency. If I have a promise-returning function promiseSomething, writing ...
4 votes
2 answers
210 views

Refactoring asynchronous JS pre-rendering code

A few months ago I wrote this module but, coming back to it, I find it a bit hard to read and reason about. I want to ask community's opinion on whether this needs to be refactored, and how I could ...
1 vote
2 answers
338 views

Can this promise be chained more cleanly?

The below code uses Promises/A+ (specifically rsvp.js) to generate a token. It does so by either taking an existing token or downloading and parsing a token from a web page. Is it possible to chain ...
2 votes
2 answers
2k views

jQuery nested ajax deffereds- looking for improvements

Following is a working solution for a single xml ajax to retrieve category list, then individual ajax calls for each category. This was developed in response to a question on SO. Solution creates one ...
6 votes
1 answer
5k views

Multiple jQuery promises

I'm starting to reuse this pattern, and was wondering if there was a more succinct/clear way to write it. Given a function foo taking a callback argument: ...
1 vote
1 answer
362 views

Simple jQuery search on input element

Just wanted a way of attaching a jQuery search plugin to an input element (or collection) and be able to pass specific options at invoke time: This is the plugin code ...