"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.

learn more… | top users | synonyms (1)

11
votes
2answers
595 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 ...
11
votes
1answer
5k 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 ...
11
votes
1answer
786 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 ...
10
votes
2answers
618 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 ...
10
votes
1answer
212 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 ...
8
votes
1answer
530 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, ...
6
votes
1answer
65 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 ...
6
votes
1answer
156 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 ...
6
votes
1answer
2k 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: ...
6
votes
1answer
186 views

Using a Wrapper Promise

I wrote some code for an application that uses the following pattern: ...
5
votes
1answer
154 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 ...
5
votes
1answer
587 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 ...
5
votes
1answer
587 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 ...
5
votes
1answer
79 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 ...
5
votes
1answer
378 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 ...
4
votes
2answers
544 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 ...
4
votes
1answer
422 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. ...
4
votes
2answers
145 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 ...
3
votes
2answers
191 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 ...
3
votes
1answer
167 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 ...
3
votes
1answer
748 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 ...
3
votes
1answer
225 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 ...
3
votes
1answer
125 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
0answers
185 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 ...
3
votes
0answers
36 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 ...
3
votes
0answers
71 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
1answer
2k views

What is the best approach to cache/memoize Promise results?

One approach it to chain cachedPromise and "regular", thus, if cachedPromise fails, we call a regular one (and caching results). ...
2
votes
1answer
212 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: ...
2
votes
1answer
31 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 ...
2
votes
1answer
143 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. ...
2
votes
1answer
64 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
1answer
289 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 ...
2
votes
1answer
129 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) ...
2
votes
1answer
88 views

My yld NPM - callbacks/promises alternative

I'd like feedback on my callbacks/promises alternative, please. The yld repository ...
2
votes
2answers
1k 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 ...
2
votes
1answer
116 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 ...
2
votes
1answer
159 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 ...
2
votes
0answers
44 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. ...
1
vote
1answer
423 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 ...
1
vote
1answer
61 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 ...
1
vote
1answer
109 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
1answer
355 views

Improving a JQuery Promise “Chain”

I have a little chain of JQuery promises. My problem is at each stage I want to notify my progress to the user, keep them in the loop (Perhaps using .notify somehow?) What I've eneded up with is ...
1
vote
1answer
309 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 ...
1
vote
1answer
59 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. ...
1
vote
1answer
58 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 ...
1
vote
1answer
46 views

Logging out using nested promises

Is it OK to do that ? for example, I have my log out service ...
1
vote
1answer
277 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 ...
1
vote
1answer
43 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? ...
1
vote
1answer
1k 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 ...
1
vote
2answers
239 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 ...