bluebird

Use ldapjs with bluebird promise

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I posted something similar here: Use ldapjs with promise . Unfortunately, it is still unsolved. This time I tried bluebird and hopefully I can get some luck. // https://www.npmjs.com/package/ldapjs var Promise = require('bluebird'); var ldap = Promise.promisifyAll( require('ldapjs') ); var config = require('./config'); var print_r = require('print_r').print_r; var my_filter = "(&(objectCategory=person)(objectClass=user)" + "(cn=" + 'someone' + "))"; var ldap_username = config.ad.username; var ldap_password = config.ad.password; var ldap_url

How to promisify a MySql function using bluebird?

ぃ、小莉子 提交于 2019-12-03 08:31:19
Some time ago I decided to switch from PHP to node. In my first projects I didn't want to use any ORM since I thought that I didn't need to complicate my life so much learning another thing (at the moment I was learning node and angular) therefor I decided to use mysql package without anything else. It is important to say that I have some complex queries and I didn't want to learn from sctratch how to make them work using one of the 9000 ORM node have, This is what I've been doing so far: thing.service.js Thing.list = function (done) { db.query("SELECT * FROM thing...",function (err,data) { if

Bluebird.js custom Error catch function, does not apply on the first promise?

谁说胖子不能爱 提交于 2019-12-03 07:38:30
I'm trying to use the custom error handlers of Bluebird.js. In the example bellow the catch-all handler is called, not the MyCustomError handler, but when I moved the rejection into the then function (and resolved the firstPromise...), the MyCustomError handler is called. Why is that? got something wrong? Thanks. var Promise = require('bluebird'), debug = require('debug')('main'); firstPromise() .then(function (value) { debug(value); }) .catch(MyCustomError, function (err) { debug('from MyCustomError catch: ' + err.message); }) .catch(function (err) { debug('From catch all: ' + err.message); }

Promises with fs and bluebird

Deadly 提交于 2019-12-03 05:49:11
问题 I'm currently learning how to use promises in nodejs so my first challenge was to list files in a directory and then get the content of each with both steps using asynchronous functions. I came up with the following solution but have a strong feeling that this is not the most elegant way to do this, especially the first part where I am "turning" the asynchronous methods into promises // purpose is to get the contents of all files in a directory // using the asynchronous methods fs.readdir()

Downloading files with node.js, streams, and promises

霸气de小男生 提交于 2019-12-03 03:07:46
Here is a snippet of my code: var processListing = function (directoryItems) { console.log('foreach'); var itemsToDownload = []; directoryItems.forEach(function (element, index, array) { //Ignore directories if (element.type === 'd') { console.log('directory ' + element.name); return; } //Ignore non zips if (path.extname(element.name) !== '.zip') { console.log('ignoring ' + element.name); return; } //Download zip itemsToDownload.push({ source: element.name, destination: element.name }); //aftpSystem.downloadFile(element.name, element.name); }); console.log('after foreach'); return

Mongodb node driver 2.0.* with Bluebird 2.9.* promisification

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So there are a few other queries around this subject such as: How can I promisify the MongoDB native Javascript driver using bluebird? However it does not seem to address the latest version of the driver, which seems to have issues when trying to promisify. Currently I can get the MongoClient working by doing: Promise.promisifyAll(mongodb.MongoClient); // Using .Prototype here fails to promisify However no matter what I try the Collections do not seem to operate using the *async calls, it may invoke them but they never get resolved or

TypeScript use dynamic import in ES5 with Bluebird

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use the new dynamic import() function in TypeScript, but I get the following error: TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option. I could include the ES2015.promise lib in my tsconfig like the message suggests, but that would make me lose type safety as I'm using Bluebird promises. I know it is possible to use Bluebird for async/await in TypeScript, so I suppose this should also work the same

Bluebird promise resolve(data) is undefined in client code

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Hiyas. I have a simple app whereby a client is expecting a promise as a result, but upon calling the resolve() method, the promise keeps returning undefined as the result. The client code: UsersRepo . findOneAsync ({ id : id }). then ( function ( err , result ) { console . log ( "UserService promise resolution" , err , result ); }); This outputs "null" and "undefined", for err and result, respectively The code that is doing the work and returning the promise: findOneAsync : function ( args ) { var where = "" ; //omitted var promise

Why do I not get the warning “a promise was created in a handler but was not returned from it”?

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Edit: to be more clear - I'm NOT getting warning in example below. I would like to know why and see example code where warning would be printed. In my Node.js project I'm using bluebird Promises library. I observed some cases where I'm getting following warning: Warning: a promise was created in a handler but was not returned from it I understand that the problem occurs when there is promise that is not connected to any promise chain. I'm trying to fully understand how this works and what exactly the problem is in mentioned case. For that

JS Promises - if-else flow when only single path is async

[亡魂溺海] 提交于 2019-12-02 16:43:30
问题 I'm rewriting some legacy code, which was build using sync ajax (so so bad). Now I'm using Promises (specifically Bluebird). There are a lot of situations, where function has a lot of paths, from which only one is async. The problem is that I have to identify all paths and manually return new promise from each of them. Like this: function syncFn() { // sync code return } function asyncFn() { // some async code here that return Promise } function myMegaFunction() { if ( ... ) { return Promise