bluebird

Monitoring pending async operations in Node.js promised environment

南笙酒味 提交于 2019-12-18 06:53:34
问题 I have built in Node.js a very stable robot app that basically sends requests continuously to an API. To make sure nothing can go wrong, I handle any possible error and I have set timeouts for promises that could take too long to resolve... Now, I would like to improve the app by removing my safety nets, and monitoring async operations to find any kind of "async leaking", eg promises pending forever or any strange outcome I'm not aware of (that's the point of my question). Are there any tools

Monitoring pending async operations in Node.js promised environment

谁都会走 提交于 2019-12-18 06:52:13
问题 I have built in Node.js a very stable robot app that basically sends requests continuously to an API. To make sure nothing can go wrong, I handle any possible error and I have set timeouts for promises that could take too long to resolve... Now, I would like to improve the app by removing my safety nets, and monitoring async operations to find any kind of "async leaking", eg promises pending forever or any strange outcome I'm not aware of (that's the point of my question). Are there any tools

Best way to handle nested Promises (bluebird) [duplicate]

依然范特西╮ 提交于 2019-12-18 03:27:04
问题 This question already has answers here : How do I access previous promise results in a .then() chain? (17 answers) Closed 4 years ago . I have the following promise chain below and it appears to be quite messy (Each _create * function returns a promise): return new Promise(function (resolve, reject) { _this.database.transaction(function (t) { _this._createExternalAccount(payment, t) .then(function (externalAccount) { return _this._createExternalTransaction(externalAccount, payment, t) .then

Best way to handle nested Promises (bluebird) [duplicate]

余生颓废 提交于 2019-12-18 03:27:03
问题 This question already has answers here : How do I access previous promise results in a .then() chain? (17 answers) Closed 4 years ago . I have the following promise chain below and it appears to be quite messy (Each _create * function returns a promise): return new Promise(function (resolve, reject) { _this.database.transaction(function (t) { _this._createExternalAccount(payment, t) .then(function (externalAccount) { return _this._createExternalTransaction(externalAccount, payment, t) .then

Manually promisifying pg.connect with Bluebird

前提是你 提交于 2019-12-18 02:54:48
问题 I want to promisify node-postgres' pg.connect method along with the inner connection.query method provided in the callback. I can .promisify the latter, but I need to implement the first one manually (if I'm missing something here, please explain). The thing is, I'm not sure if this code is correct or should be improved? The code is working, I just want to know if I'm using Bluebird as meant. // aliases var asPromise = Promise.promisify; // save reference to original method var connect = pg

Bluebird Promisfy.each, with for-loops and if-statements?

て烟熏妆下的殇ゞ 提交于 2019-12-18 02:49:47
问题 Right now, the parent for-loop ( m < repliesIDsArray.length ) completes before the first findOne fires, so this all only loops through the last element of the repliesIDsArray..asynchronous.. What's the proper syntax for a promisified version of this codeset? Am new to promisification, and wondering how to start this promisify + loop through arrays + account for if-statements.. Bluebird is required, and Promise.promisifyAll(require("mongoose")); is called. for(var m=0; m<repliesIDsArray.length

Trigger Promise when an event fires

﹥>﹥吖頭↗ 提交于 2019-12-17 23:31:54
问题 My entire project uses (Bluebird) Promises, but there's one particular library that uses EventEmitter. I want to achieve something like: Promise.on('connect', function() { x.doSomething(); }).then(function() { return new Promise(function(resolve) { y.doAction(resolve); // this will result in `eventB` getting emitted }); }).on('eventB', function() { z.handleEventB(); }).then(function() { z.doSomethingElse(); }); I read the answer to EventEmitter in the middle of a chain of Promises. That gives

Use cancel() inside a then-chain created by promisifyAll

别等时光非礼了梦想. 提交于 2019-12-17 22:01:47
问题 Not sure if I'm clear enough with this title, but assume that I have a class called Foo with method1 , method2 and method3 . I promisify its methods with promisifyAll . Then I have a then-chain and I want to cancel the operation in the middle of the second or first then, and no further then should be called. I read about Cancellation (http://bluebirdjs.com/docs/api/cancellation.html) but I don't know how to implement it with promisifyAll. The code I got plus what I need: var bluebird =

Poll for a result n times (with delays between attempts) before failing

大城市里の小女人 提交于 2019-12-17 21:00:13
问题 We need to write a Node.js function that polls a certain API endpoint for a result of a previously requested calculation. The result takes a random time to be generated and may not me generated at all. We'd like to get it as soon as possible, but also I don't want to wait for too long, which means that after a certain number of API calls we'd like the function to fail (reject a Promise). There is one way communication between our code and the API. const Bluebird = require('bluebird');

How will a promisified mysql module work with NodeJS?

元气小坏坏 提交于 2019-12-17 20:16:10
问题 I'm trying to work with MySQL in NodeJS. My entire app is built with promises, so I want to promisify the mysql module as well. So I have this: Promise = require('bluebird'); var mysql = Promise.promisifyAll(require('mysql')); Now, according to their API, the connect() method accepts a single parameter, an err callback to be called in case of connection error. My question is, how does that translate to promises? Will the promise be resolved on error? Will it be rejected? Will I need to .catch