"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.
0
votes
0answers
22 views
Javascript / Promises
I'm working on converting a simple Python script into nodejs 4.4.5 with es6 features like Promises.
The original Python script did the following:
Contact a 3rd party SOAP service
Attempt to ...
0
votes
0answers
17 views
Promisify NodeJS and Mongose callback even further
I've recently started to experience writing Node.js code, and JavaScript in general.
Right now I am planning to promisify (with Q) some of the node.js callback code I had, and I come to this.
The ...
0
votes
0answers
51 views
Register a node-client code through an API call efficiently?
I've got a node_module that reads ArcValues for a user and updates the config of the node client at user's local (root). Like so:
...
4
votes
1answer
59 views
Javascript promises, multiple api calls in then()
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 when" and it doesn'...
2
votes
0answers
22 views
Wrapping a node.js module
I need to use elasticseach in my node.js project, whose API looks like the following:
...
0
votes
1answer
55 views
ES6 Promise with the “co” module
I was trying to use the ES6 Promise with the "co" module to write the async code without callback. Though actual async call is neat and clean, I still have to add ...
-2
votes
1answer
37 views
Code Sample - promise chain / Angular
I am putting together a couple code samples for prospective employers and would love some feedback. I am still pretty junior so I am not sure what constitutes a good code sample and the do's and dont'...
1
vote
1answer
51 views
Check if images are loaded (ES6 Promises)
I wrote a small function that checks if an image or multiple images are loaded. For that purpose, I decided to use ES6 promises, but I'm not really sure if my way of handling errors is the best way.
<...
0
votes
0answers
31 views
1
vote
0answers
21 views
Getting data from service and storing it in MongoDB
I wrote code to get data from HTTP service and store it in MongoDB. Please, can someone let me know how efficient my code is and whether it is good from the OOP point of view?
...
4
votes
0answers
44 views
Prevent multiple async calls from all attempting to refresh an expired OAuth token
I have some code that needs to access an API that requires OAuth authorization in the form of a token, and every time the token expires, it needs to be refreshed.
I made a function called ...
4
votes
1answer
49 views
2
votes
1answer
71 views
Using fetch() and a new Promise object to get API results
I've written an ES6 function using the new fetch() API and returning a new resolved promise with a data object or a rejected promise with an error subclass.
I'm pretty new to both ES6 and Promises, ...
2
votes
1answer
54 views
Promise.spread “Polyfill”
I have written this "Polyfill" for Chrome's Promise object and I have some concerns about the implementation;
Does it actually work as designed? It seems to work ...
1
vote
0answers
44 views
Recursion into git diff tree using nodegit
I'm using nodegit to develop the backend for a nodejs app that uses a mix of mongodb and git for persistence. The app has to version documents and be able to present diffs between versions, thus the ...
1
vote
1answer
43 views
Callback of setTimeout function when performing synchronous actions
Inside a function I'm calling playgame service. Once I've obtained the needed data (gameBeingPlayed), I need to show a 3..2..1 counter and then start a game.
...
2
votes
1answer
22 views
Parallel computation to be merged, depending on single call
Steps:
Get AMOUNT from a call to API endpoint /a, e.g. AMOUNT == 5 (in the code it is set ...
2
votes
1answer
57 views
Asynchronous database lookups in Node.JS using Promises
Not confident enough if this would be the correct 'node way' of writing Promises:
Essentially, there are two async database calls, the result from both of these ...
3
votes
1answer
76 views
3
votes
0answers
101 views
Bill has a hard time keeping all his promises
Description
A couple days ago I created this Angular 1.x provider for my Ionic/Cordova app. I'm using webpack and babel-loader for ES6/ES2015 syntax and modules.
All my provider does is "provide" an ...
0
votes
0answers
180 views
Bluebird promises: generalized retry logic with timeout
I'm attempting to write an idiomatic utility that uses bluebird promises to retry asynchronous logic until it is successful, or until a set timeout expires. Currently I'm looking at:
...
1
vote
1answer
96 views
Handle API timeouts in Node Sails.js
I am working on a node.js sails.js app that handles a number of API calls and uses Bluebird for promises. The API calls have been reliable but I would like to build in handling for if they do not ...
2
votes
1answer
88 views
Probe for open application on a TCP port
I need to examine an application port to see if it opens and I need to put the retry count as a parameter. Since I'm new to Node I wanted to get your feedback on it
for improvements.
...
3
votes
1answer
80 views
Loading a database table using a promise chain
I am creating a util module that I'm using to communicate with a MS-SQL database. I want each public method to return a promise. I started with a private function that executes a DB query and returns ...
4
votes
3answers
214 views
Performing data transportations in RxJS with Promises
I'm using RxJS 5.0.0-alpha.12 to perform some data transformations, and some of those transformations use Promises.
...
7
votes
1answer
347 views
Sails.js controller method for an admin to update a user account
I am new to Sails.js, Node.js, and web application development in general. My current understanding is that well-written controllers should be "skinny" meaning they should be as simple as possible, ...
4
votes
2answers
38 views
Promises turning into pyramids
I'm using node-ftp to download some files from an FTP server; due to nodeback difficulty and nested calls I'm promisified some of the calls, hoping that this will help get me out of pyramid code hell, ...
6
votes
1answer
245 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
57 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
254 views
Bluebird: promisify xhr request
I use bluebird promises. I want to promisify my requests from communication layer:
Utils.js
...
2
votes
1answer
25 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
517 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
2answers
621 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
117 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
460 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
29 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.
...
1
vote
1answer
76 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
158 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
36 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:
...
1
vote
0answers
41 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
26 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
83 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
1answer
952 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 ...
2
votes
1answer
531 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
872 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
84 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
4k 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
200 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
164 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 ...