bluebird

return value inside promise chain isn't getting called

一曲冷凌霜 提交于 2019-12-04 00:58:23
I'm using the promise library Bluebird and I'm currently running into the issue that everything inside the function runs great, but when I try to return a value, the function instead returns undefined . This is the promise chain: function foo() { createGroupMembers(parsedChat).then(function(val) { var members = val; createMessages(parsedChat, maxPages).then(function(val) { var messages = val; Promise.all([ createFrontCover(subject, firstdateOfMessages, lastDateOfMessages, isPreview), createStats(parsedChat), createBackCover(parsedChat)]) .then(function (results) { var front = results[0]; var

Promises in Sequelize: how to get results from each promise

亡梦爱人 提交于 2019-12-04 00:46:36
In Sequelize >=1.7 we can use promises Can you explain for me how can i get values from each user in this code: var User = sequelize.define("user", { username: Sequelize.STRING }) User .sync({ force: true }) .then(function() { return User.create({ username: 'John' }) }) .then(function(john) { return User.create({ username: 'Jane' }) }) .then(function(jane) { return User.create({ username: 'Pete' }) }) .then(function(pete) { console.log("we just created 3 users :)") console.log("this is pete:") console.log(pete.values) // what i want: console.log("this is jane:") console.log(jane.values)

Co.js and bluebird.js — what's the difference?

坚强是说给别人听的谎言 提交于 2019-12-03 15:01:50
Could someone help me understand the differences between using Koa.js and Bluebird.js with ES6 Harmony. Specifically, how does co( function * () { //stuff } ); compare to, Promise.coroutine( function * () { //stuff } ); It just seems Koa should be using Bluebird and not recreating the wheel. What's different? For now the difference is that Koa allows yielding more than just promises. However a feature is being added that allows not only yielding callbacks, thunks etc but any arbitrary thing that comes to your mind. Bluebird is also the fastest. So after this version koa should be just using

Retrieve paginated data recursively using promises

女生的网名这么多〃 提交于 2019-12-03 14:05:02
问题 I'm using a function which returns data in a paginated form. So it'll return max 100 items and a key to retrieve the next 100 items. I want to retrieve all the items available. How do I recursively achieve this? Is recursion a good choice here? Can I do it any other way without recursion? I'm using Bluebird 3x as the promises library. Here is a snippet of what I'm trying to achieve: getEndpoints(null, platformApplication) .then(function(allEndpoints) { // process on allEndpoints }); function

Downloading files with node.js, streams, and promises

谁说我不能喝 提交于 2019-12-03 13:02:17
问题 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 }); /

How to bulk insert in mySql and node.js using mysljs

狂风中的少年 提交于 2019-12-03 12:53:20
Im not able to use bulk insert in my DB using node.js lib mysljs . I followed answers from: How do I do a bulk insert in mySQL using node.js with no success. var sql = "INSERT INTO resources (resource_container_id, name, title, extension, mime_type, size) VALUES ?"; var values = [ [1, 'pic1', 'title1', '.png', 'image/png', 500], [1, 'pic2', 'title2', '.png', 'image/png', 700]]; return connection.query(sql, [values], (result) => { if (err) throw err; connection.end(); }); I keep getting error: 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server

Testing rejected promise in Mocha/Chai

旧街凉风 提交于 2019-12-03 11:02:24
I have a class that rejects a promise: Sync.prototype.doCall = function(verb, method, data) { var self = this; self.client = P.promisifyAll(new Client()); var res = this.queue.then(function() { return self.client.callAsync(verb, method, data) .then(function(res) { return; }) .catch(function(err) { // This is what gets called in my test return P.reject('Boo'); }); }); this.queue = res.delay(this.options.throttle * 1000); return res; }; Sync.prototype.sendNote = function(data) { var self = this; return self.doCall('POST', '/Invoice', { Invoice: data }).then(function(res) { return data; }); }; In

How to cast jQuery $.ajax calls to Bluebird promises without the deferred anit-pattern

浪子不回头ぞ 提交于 2019-12-03 10:51:10
Right now I use promise.deferred in a core file. This allows me to resolve promises at a central location. I've been reading that I may be using an anti-pattern and I want to understand why it is bad. so in my core.js file I have functions like this: var getMyLocation = function(location) { var promiseResolver = Promise.defer(); $.get('some/rest/api/' + location) .then(function(reponse) { promiseResolver.resolve(response); )} .catch(function(error) { promiseResolver.reject(error); }); return promiseResolver.promise; } And then in my getLocation.js file I have the following: var core = require(

Nodejs exec mongodb command in Bluebird Promise

匿名 (未验证) 提交于 2019-12-03 10:10:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to run mongod command in node.js using Promises, so that database operations can run only after mongodb process is started. I tried my hands with following, but failed: var Promise = require("bluebird"); var execAsync = Promise.promisify(require('child_process').exec); execAsync("~/mongodb/bin/mongod").then(function(result){ console.log("started mongodb..."); }).catch(function(error){ console.log("error in starting mongodb..."+JSON.stringify(error)); }); Any suggestions? 回答1: You shouldn't start your mongod process in node, you should

I Broke My Promise

∥☆過路亽.° 提交于 2019-12-03 10:05:43
So.. I'm having the hardest time learning how to Promise. I'm using bluebird ( https://github.com/petkaantonov/bluebird ) as suggested to me -- in order to tame my callback hell I've been getting. Example: function login(req,res,con,mysql,P) { var ref = undefined; con.getConnection(function(err,connection) { if (err) console.log("Get Connection Error.. "+err); con.query('SELECT password,id FROM player WHERE name='+mysql.escape(req.body.user),function(err,rows,fields) { if (err) throw err; if (!rows[0]) { res.send({ "msg":"Your username and or password was incorrect.", "flag":true, "title":":