Is there a "definitive" model for the promises?

Imagine the following Promise-based example: function treadLightly() { return Promise.resolve() .then(function() { allocateResource(); }) .then(function() { doRiskyOperation(); }) .then(function() { releaseResource(); }) .catch(function() { releaseRe

Returning the promise of the function

I have a shallow understanding of JavaScript Promise and promise chain. Say, I have a method as shown below. It's written is TypeScript, but could be modified to match JavaScript ES6 private InsertPersonInDB(p : Person) { return this.db.find({ //<- w

How to avoid the "reminder of hell" with promises?

This question already has an answer here: Removing nested promises 2 answers I'm new to Promises and would like to understand what is the correct way to avoid the 'callback hell' with promises, since I'm having the same exact problem as using callbac

Transmit variables in Promise

This question already has an answer here: How do I access previous promise results in a .then() chain? 15 answers I am using promise-mysql in my application where I need to query the information of a book, and then retrieve some books with the same a

Recursive $ http.get in the loop

I use Angular 1.5. I have a function that queries Categories, then for each category, it queries Products. I want to show a message after all the products are retrieved, how many were retrieved. It outputs 0. What is the solution? function getProduct

How can I limit the api request stack?

I have an array of ids, and I want to make an api request for each id, but I want to control how many requests are made per second, or better still, have only 5 open connections at any time, and when a connection is complete, fetch the next one. Curr

How to return simple values ​​from bluebird promises?

I am new to promises. I am using Bluebird promises for running an async function in this fashion. var contract_creation = function creation(contractName){ return new Promise(function (resolve,reject){ web3.eth.sendTransaction( { from: web3.eth.accoun

Promises: go to the next error function

This question already has an answer here: Chained promises not passing on rejection 3 answers How would you make a call to the next error function with promise chaining? I thought a return inside the error function would automatically call the next e

Retrieving Multiple API Requests with React Native

Here is an outline of my code (sparing some details). Basically I just want to make two similar API requests when I click a button, then have a function that works with the results of both the requests, but I cannot figure it out. class myClass exten

Why is my Promise definition executed?

I am quite new with Promises and want to know why is it that my Promise definition gets executed without me calling a .then() or resolve on it. var promise = new Promise(function (resolve, reject) { console.log("Starting loader"); resolve(); });

Why Promise.resolve (). Then () is delayed?

I don't understand why resoved Promise delay .then() argument call? example: var myPromise = Promise.resolve(); console.log(myPromise); myPromise.then(()=>console.log('a')); console.log('b'); console return: > Promise { <state>: "fulfille

How to chain the promise error functions in angularjs

I know how to chain promises so that multiple success functions are executed. That is esplained in many examples. How do I chain promises so that multiple error functions are executed?When an error is handled (and, either a value is returned or no va

Control-Flow with NodeJS and Sequelize

I have the following function: function retrieveNotifications(promotions) { promotions.forEach( function(promotion) { //find all notification groups that have to be notified db .Notification .findAll() .then(function (notifications) { //some code tha

Recursive replay in Promise

Now I am learning how to write JavaScript code with promise. Here is my case, the deliverMessage function in Sender try to connect with amqp. If success, then call publish_ to send messages. Otherwise, call reconnect_ to reconnect to amqp after 3 sec

Angular - Make multiple request on app.run ()

On my app, I need to recover data (json) by making multiples validations using http requests before all my app starts. So my problem is that I'm using angular.run() to make all the http requests and resolving all of the validations with promises. The

Angular promise chaining with past parameters

In my Angular application I am trying call a series of functions, each one returning a value which becomes the input for the next one. Conceptually it is something like this: $scope.createPanel = function() { var primer3_parameter_id = primer3FromDes

AngularJS validation and promises

In an Angular app, form is validated via custom JS function before submitting. Based on a condition, I need to show a confirmation dialog to the user, wait for confirmation or rejection, then proceed with validation. I'm having difficulties with achi

Angular / jasmine / promise / mockery test

I'm a little screwed up with angular / jasmine / promise / mocking testing. I have a piece of code: factory.login = function(user, pwd) { AuthenticationResource.login( {}, {"username" : user, "password" : pwd}, factory.onLoginSuccess,

How to determine if a Promise is supported by the browser

Does anyone know, using Modernizr or otherwise, if there is a way to detect if the Promise feature is enabled in a browser? I have a polyfill for the functionality, but only want to apply it if the browser does not have a native implementation.Update

How to synchronize the MongoDB asynchronous query in NodeJS

I have a for-loop statement and an async MongoDB inside loop body. What I want to do is to make a find query from my MongoDB database, and push the result into an Array. Here is the code: function() arrResult() { var arr = []; for(...) { collection.f

Loop and chain Ajax calls using deferred

I've seen many questions about this but nothing seems to give the right answer for my case. I've seen also answers that uses .pipe but I'm looking for an answer that uses .then. Okay. I need to do 3 ajax calls, lets say a poll application that allows

How to use jQuery .When .done

I'm trying to run one function after another function completes. $.when(saveCanvas(canvas)).done(setWallPaper()); Each function works fine on it's own but when I run the code above it only runs the first function. What do I need to change?According t

jquery postponed the failure of the turn in the success

So in using jQuery deferreds and $.when to load many objects in parallel. $.when( a.ajax(), b.ajax(), c.ajax() ).then( //do something when all are complete complete(); ); Now, b.ajax() will sometimes fail, but I dont actually care. I just want to wai