bluebird

Promise has no method 'sort'

妖精的绣舞 提交于 2019-12-05 19:08:59
I am using Mongoose with Bluebird and am hitting an Error when using a query that includes a sort on a time stamp. I am trying to retrieve only the most recent entry. The query works when using the built in Promises. Any ideas? Thanks! var Promise = require("bluebird"), mongoose = require('mongoose'); var Item = Promise.promisifyAll(mongoose.model("Item")); Promise.promisifyAll(Item.prototype); var connect = function () { var options = { server: { socketOptions: { keepAlive: 1 } } }; var mongoUrl = "mongodb://" + config.mongo.host + ":" + config.mongo.port + "/" + config.mongo.db; mongoose

Meteor with Promises

筅森魡賤 提交于 2019-12-05 18:29:23
I've been trying to get into the habit of using promises but ran into problems while trying to use them in server side code in the context of Meteor. This is the problem: if (Meteor.isServer) { Meteor.startup(function () { // code to run on server at startup p = function(){ return new Promise(function(res,rej) { res("asd"); }); }; p().then(function(asd){ console.log("asd is " + asd); return "zxc" }).then(Meteor.bindEnvironment(function(zxc){ console.log("zxc is " + zxc); return "qwe" })).then(function(qwe){ console.log("qwe is " + qwe); }); }); } mvrx:bluebird package is installed code also

Promises in Sequelize: how to get results from each promise

对着背影说爱祢 提交于 2019-12-05 17:30:06
问题 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:"

Bluebird Promises Join behaviour

北战南征 提交于 2019-12-05 17:03:42
问题 If I execute the following code with Node.js var Promise = require('bluebird'); Promise.join( function A() { console.log("A"); }, function B() { console.log("B"); } ).done( function done() { console.log("done");} ); The console will log B done However I would expect A B done or B A done If it set a break point in function A it is never reached. Why is it that it processes B but not A? 回答1: Promise.join takes promises as all its arguments but its last one, which is a function. Promise.join

return value inside promise chain isn't getting called

怎甘沉沦 提交于 2019-12-05 16:24:55
问题 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),

Setting a timeout for each promise within a promise.all

久未见 提交于 2019-12-05 11:33:57
I am able to successfully perform a Promise.all, and gracefully handle resolves and rejects. However, some promises complete within a few milliseconds, some can/could take a while. I want to be able to set a timeout for each promise within the Promise.all, so it can attempt to take a maximum of say 5seconds. getData() { var that = this; var tableUrls = ['http://table-one.com','http://table-two.com']; var spoonUrls = ['http://spoon-one.com','http://spoon-two.com']; var tablePromises = that.createPromise(tableUrls); var spoonPromises = that.createPromise(spoonUrls); var responses = {}; var

Use ldapjs with bluebird promise

a 夏天 提交于 2019-12-05 10:36:41
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 = config.ad.url; var ldap_dn_search = config.ad.dn

Bluebird's Promise.all() method when one promise is dependent on another

风流意气都作罢 提交于 2019-12-05 10:33:41
I'm writing some code that currently looks like this because I have dependencies in my code. I was wondering if there was a cleaner way to do this with Promise.all()? Here is my pseudo code: return someService.getUsername() .then(function(username) { user = username; }) .then(function() { return someService.getUserProps(user); }) .then(function(userProps) { userProperties = userProps; return someService.getUserFriends(user); }) .then(function(userFriends) { friends = userFriends; }) .catch(error) .finally(function(){ // do stuff with results }); The important thing is that I need user before I

Unhandled rejection error Bluebird

强颜欢笑 提交于 2019-12-05 10:14:30
I have the following code. And it works as expected without throwing a unhandled rejection error. p = new Promise (fulfill, reject) -> reject new Error 'some error' p.catch (error) -> console.log error Now, the second code example does throw an unhandled rejection error. Can someone explain to me why this is happening when im clearly handling the error. p = new Promise (fulfill, reject) -> reject new Error 'some error' p.then -> console.log 'ok' p.catch (error) -> console.log error Btw. I'm testing in chrome and bluebird v3.4.7 When you chain Promises , each chain is treated as new instance of

Wrapping Node.js callbacks in Promises using Bluebird

烈酒焚心 提交于 2019-12-05 05:02:13
How do I wrap a Node.js callback using a Promise in Bluebird? This is what I came up with, but wanted to know if there is a better way: return new Promise(function(onFulfilled, onRejected) { nodeCall(function(err, res) { if (err) { onRejected(err); } onFulfilled(res); }); }); Is there a cleaner way to do this if only an error needs to be returned back? Edit I tried to use Promise.promisifyAll(), but the result is not being propagated to the then clause. My specific example is shown below. I am using two libraries: a) sequelize, which returns promises, b) supertest (used for testing http