"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.
6
votes
1answer
85 views
A simple weather app in Node.js
while practicing Promises, I ended up with a simple weather application which works on the command line. I would highly appreciate it if you can point out any flaws ...
0
votes
2answers
48 views
Anti-pattern or acceptable way of using Promises? [closed]
Whenever I need to use a Promise interface in my NodeJs code and I don't have a promise to start off with, I do this:
...
4
votes
2answers
46 views
Bluebird: promisify xhr request
I use bluebird promises. I want to promisify my requests from communication layer:
Utils.js
...
2
votes
1answer
15 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 ...
0
votes
1answer
89 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 ...
4
votes
1answer
119 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 ...
2
votes
3answers
92 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
0answers
108 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 ...
0
votes
0answers
17 views
Angular controller to fetch information on conractors [sic] and projects
In my Angular controller, I am using 3 different functions to get the data. It works fine, but is there a way to simplify this?
...
0
votes
0answers
25 views
Mapping a promise to an object
Below is a demonstration of how to map over an object when you want one of the values to be a promise.
...
0
votes
1answer
39 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
1answer
156 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 ...
1
vote
0answers
33 views
Making all directories to a path
Below are two promises: the first does a bit of nesting and the second is all anon then calls that return one function in them. Which do you prefer? Any improvements?
Promise A:
...
0
votes
0answers
23 views
Chain-able promise file system functions
I'm trying to invent an easier way of working with the file system. Here I chain promise methods together.
...
1
vote
0answers
20 views
Find specific promise in array that contains both resolved and rejected values
I basically want to find a specific promise in a given array of promises. The thing is that (I'm using bluebird promises, but the same hold true for anouther standard implementations):
it is ...
1
vote
1answer
74 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.
...
3
votes
0answers
481 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 ...
1
vote
1answer
163 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 ...
2
votes
1answer
283 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 ...
1
vote
1answer
74 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
1k 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
0answers
79 views
Appropriate use of bind for elasticsearch callback
I'm starting a new project with Node. I'm learning the object model, and the code below is my first module. One of the things threw me was the behavior of this ...
6
votes
1answer
96 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
1answer
59 views
3
votes
0answers
50 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 ...
1
vote
1answer
114 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
0answers
157 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 ...
1
vote
1answer
395 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 ...
4
votes
1answer
481 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 ...
1
vote
0answers
44 views
Sign-up controller and service
I'm programing server side node for a huge project. And I'm thinking my brains out about the best programming pattern that will be suitable for fast modification and changes.
Tell me what you think ...
2
votes
0answers
52 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
53 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?
...
3
votes
0answers
92 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:
...
4
votes
2answers
1k 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 ...
0
votes
0answers
58 views
Error handling in directory iterator using promises
I wrote this example of IS.File.directoryIterator for Firefox.
Can you please help me to review it so if an error occurs it is caught? I'm not so great with ...
5
votes
1answer
774 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
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 ...
3
votes
1answer
161 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 ...
5
votes
1answer
918 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
2answers
790 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
1answer
57 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
1answer
91 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 ...
6
votes
1answer
214 views
2
votes
1answer
165 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.
...
8
votes
1answer
696 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, ...
2
votes
1answer
75 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 ...
12
votes
1answer
7k 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
1k 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 ...
3
votes
2answers
229 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
190 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 ...