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
5 votes
1 answer
173 views

Promises with Express/Mongoose to send comment notifications

I'm building the backend for a mobile app project. Below is my createComment controller. The challenge for me is that I want to send notifications out to the <...
3 votes
1 answer
306 views

ES6 cron module

I just created my first ES6 module in Node, and first time using promises and I was hoping to get some feedback on it. I am the only developer at my current company, so I cannot get feedback here. I ...
9 votes
1 answer
38k views

Mongoose: find() and count() query

Background I have a query in Mongoose that finds a set of objects, and then returns these said objects together with the total number of them: ...
-4 votes
1 answer
94 views

Guide for Tidying up code with promises and exports (nodejs) [closed]

I managed to get this code working. But I would like to find out how to tidy it up. Please give me some guide. In index.js, I have this code: ...
2 votes
1 answer
2k 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 ...
3 votes
1 answer
567 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 ...
4 votes
1 answer
273 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 ...
0 votes
2 answers
72 views

Achieve error differentiation in Promises

Background I have a REST API using MongoDB, Node.js and Express that makes a request to my NoSQL DB and depending on different results, I want to differentiate which error I send the customer. ...
4 votes
1 answer
62 views

Create a person if no duplicate exists

I am new to promises and although I am enjoying the simplicity after dealing with callback hell I am having some issues trying to chain them together as you can see by the mess below. So basically ...
3 votes
0 answers
289 views

AngularJs: Preventing multiple $q.get() per url

I've wrote a pretty useful method to prevent multiple requests per single get url. There is a well known pattern - to store promise and return it for each next ...
8 votes
3 answers
677 views

Node.js module using Promises (client for KeePassHttp)

This is my first Node module, as well as the first time using Promises in Javascript. It is a client for the KeePass plugin "KeePassHTTP" to expose passwords securely, which I am planning on using to ...
9 votes
1 answer
2k 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, ...
5 votes
1 answer
807 views

`std::move_as_tuple` and `std::when_all`

Working with futures and .then, I keep running into the problem of needing to "capture by move" in a lambda. In fact, not only that, but when implementing e.g. <...
3 votes
1 answer
191 views

jQuery wait for all paginations

I want to download data for all of my repos from the Github API. Github paginates their responses and includes a header Link type:"next" when there's another page ...
0 votes
1 answer
3k views

Node.js Sequelize Promise

I am working on sending a reset token via email to a potential user in Node.js, Sequelize, and Express. The code works, but I still think it could be improved by handling the promises better. ...
1 vote
1 answer
63 views

Promise Chaining Forgot Password

I have a route I've rewrote to use promises. ...
2 votes
0 answers
176 views

Chaining multiple async calls and data manipulation within promises

Is there a better way to do this (clean, efficient, good practices)? ...
3 votes
1 answer
87 views

Logging a user in and creating a session

I have a bunch of functions that return promises and need to chain them together. However, it's currently difficult to read and I would expect it to be even harder to maintain. I have a function that ...
1 vote
0 answers
340 views

Queue that permits at most X simultaneous operations

I ran into this once (permits=N) and then again today (permits =1) where I only want 1 to N operations running simultaneously. One example comes from firing into a state machine (the permit=1 example)...
8 votes
2 answers
307 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
1 answer
165 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 ...
2 votes
1 answer
12k 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 ...
3 votes
0 answers
243 views

Wrapping a node.js module using elasticsearch

I need to use elasticsearch in my node.js project, whose API looks like the following: ...
-1 votes
1 answer
93 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'...
1 vote
0 answers
453 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
1 answer
252 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: ...
2 votes
0 answers
65 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: ...
3 votes
1 answer
390 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. ...
3 votes
2 answers
613 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 ...
0 votes
1 answer
2k 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 ...
1 vote
2 answers
69 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. ...
2 votes
1 answer
4k 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
1 answer
2k 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
1 answer
73 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
1 answer
94 views

JSON API client to manage user accounts

I have the following class in Typescript (using the Aurelia SPA-framework). ...
4 votes
1 answer
13k 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: ...
12 votes
2 answers
2k 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 ...
1 vote
1 answer
110 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. ...
3 votes
1 answer
100 views

Chain of promises

Often I end up with ...
2 votes
1 answer
752 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 ...
4 votes
1 answer
135 views

Conditional async validation function

We have the following validation function: ...
2 votes
1 answer
329 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 ...
20 votes
1 answer
65k 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
1 answer
36 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
1 answer
2k 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
1 answer
189 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. ...
2 votes
1 answer
142 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 ...
4 votes
2 answers
246 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, ...
4 votes
2 answers
3k 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 ...
5 votes
1 answer
680 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 ...