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

8
votes
1answer
86 views

Yet Another Todo API

I've been on an adventure trying to learn NodeJs and put together a stack that I'd be happy to put into production if one day my team said to me "Let's build it in Node!". What we have here is your ...
1
vote
1answer
17 views

MUD Telnet game

I'm new in JS and my daily job is PHP, so I decided to do simple MUD Telnet game to practice my JS skills. The idea was to use async/await to do Telnet server code that seems synchronous at first ...
0
votes
0answers
31 views

List all files matched by glob within JSON file

Based on a set of globs contained in a custom field within a package.json file, I'm trying to get a list of all the files that the glob matches. In my continual quest to get more familiar with ...
1
vote
1answer
24 views

Using Bluebird with fs to read a file within each of an (variable length) array of directories

I'm reading an array (of unknown length) of modules package.json files in order to extract the "style" property and store it in an array of its own: ...
3
votes
0answers
10 views

Promises in mongoose

I've implemented a promises in mongoose to reduce the amount of callback hell but I am not sure whether my technique is correct. The scenario: Before I can save my schema I want to run some ...
2
votes
0answers
28 views

Cache for slow API

I work with an API which answers really slowly. I created a module which constantly asks the API and update some cached value. The code is degraded for study purposes: ...
2
votes
0answers
17 views

Parallel and Sequential array looping with async/await

Are these good implementations of parallel and sequential "extension" methods, and do they accomplish what I think they do? My understanding is that the first one is parallel because the await ...
4
votes
2answers
102 views

Plotting JSON locations using Google Road API with Javascript Promise chaining

I wrote this code for an personal application, just to help me visualize some data related to driving. I have one JSON on my machine, this JSON contains a set of locations (lat, lngs) and every ...
3
votes
1answer
90 views

AngularJS recursive function call with $timeout

I have created a recursive function call in AngularJS and just wonder if is there a better way to solve this problem? The code works perfectly. My code is the following: ...
1
vote
1answer
115 views

Basic web scrape project written in NodeJS

Here is a short program web scraping program written in Node.js. I'm just getting to grips with node and this is the first thing I've written with it. I'm liking it so far though I guess I'm kinda ...
0
votes
1answer
53 views

Detect the last resolve in an ES6 promise chain

I searched but failed to find a canonical pattern for ES6 promise-based queue. In fact all I am making is a step-wise FIFO buffer to ensure that messages don't collide so a very simple queue ...
0
votes
0answers
35 views

JavaScript making http(s) request: requiring modules within a function

This JavaScript code is being used as part of a reporting tool that makes http(s) GET requests to an API, bundles responses and uploads them as files to an AWS S3 bucket. It's a script that runs ...
3
votes
0answers
94 views

React component to list TV shows from a JSON result

I'm trying to rewrite my old project in Reactjs. As I am a beginner and this is my first app, I need some assistance in understanding what is the best way to do this in the React way and how I can ...
1
vote
2answers
31 views

XMLHTTPrequest create own service

I'm trying to create my own service, $hR. This service uses XMLHTTPrequest to get data from a URL with promise. ...
3
votes
2answers
49 views

Calling a promise recursively

I'm trying to call a promise recursively. If I get a responseData with a key error I want to call the promise again and again until I don't get it. ...
1
vote
1answer
173 views

Using promise all with push array

The code's purpose is to call to some function async given some condition was true. I've using the following code which is working as expected. Is there a way to write it better, maybe by not using ...
1
vote
0answers
93 views

Node.js MySql code using Promise API

I have written a javascript code for fetching data from mysql database. I have used connection pooling, and Promise API also. the code is as follows, ...
3
votes
1answer
76 views

From Callbacks to Promises - MEAN Stack

I have a MEAN Stack app in which I have been using mongoose routes to update my data. Some of those routes have a lot of back and forth in terms of updating data across multiple users and collections. ...
2
votes
1answer
115 views

Check deep object property and find duplicate value

I use the following code to find if there is duplicate value in property path: ...
1
vote
1answer
369 views

Promise Chaining for a Firebase v3 Auth Subsystem - Password Based Users

Firebase v3 Offers Authentication via 3rd party oAuth providers, facebook, github,google, and twitter. They also offer password pased authentication. Authenticated users have a firebase.User object ...
1
vote
1answer
40 views

Angular Promise trying Wrapper

Sometimes I need to repeat an execution of rejected promises several times, for example, to fetch some data over internet. There is a wrapper, which accepts Promise and tryCount: ...
3
votes
1answer
67 views

JSON API client to manage user accounts

I have the following class in Typescript (using the Aurelia SPA-framework). ...
0
votes
0answers
79 views

Saving an object using a promise chain

This here is some fairly simple functionality The user has a list of objects, which they modify, or may create a new object. When the user presses 'Save/Update' the 'saveClick()' function is called. ...
1
vote
2answers
72 views

Pseudo Promise.all() polyfill

A few years back I interviewed with a company for a Javascript position. After a couple of warm-up challenges I was presented with this: Please write a function that calls back with ...
2
votes
1answer
442 views

Fetch: how to deal with a json payload in an error response?

Trying to get https://github.com/github/fetch working with an API that almost always returns a json payload, even when the response is an error: ...
0
votes
0answers
72 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 retrieve ...
0
votes
0answers
28 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
57 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
165 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
50 views

Wrapping a node.js module using elasticsearch

I need to use elasticsearch in my node.js project, whose API looks like the following: ...
0
votes
1answer
134 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 ...
-1
votes
1answer
49 views

Reservation booking code samples

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'...
2
votes
1answer
319 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. <...
1
vote
0answers
23 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? ...
5
votes
1answer
131 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
62 views

Conditional async validation function

We have the following validation function: ...
2
votes
1answer
1k 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
99 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
77 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
49 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
24 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
70 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
85 views

Chain of promises

Often I end up with ...
4
votes
0answers
124 views

Bill has a hard time keeping all his promises

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 alternative ...
0
votes
0answers
453 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
207 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
107 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
241 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
336 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
615 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, ...