Hi everyone,
In my application i am using bluebird and rxjs. I am trying to return bluebird promise as observable but i get a warning
(node:34520) Warning: a promise was created in a handler at Users/gaspergracner/Projects/node_modules/rxjs/observable/PromiseObservable.js:66:36 but was not returned from it, see http://goo.gl/rRqMUw
at Function.Promise.attempt.Promise.try (/Users/gaspergracner/Projects/node_modules/bluebird/js/release/method.js:29:9)
this is what causes a problem:
public getUserByUsername(username: string): Observable<any> {
let $obs = Observable.fromPromise(User.findOne({
where: {
username: username
}
}));
return $obs;
}
Maybe you know how to avoid this warning?
.then(params => {});
, I want to add a property to params
, where the value is a promise that processes another property of params
as argument. I'm having a hard time wrapping my head around this. For example, assume params
is passed in as { prop1: [{},{},{}] }
initially. I want to return a promise that eventually resolves to { prop1: [{},{},{}], prop2: ["","",""] }
, where prop2
was evaluated from a promise that depended on prop1
. How could I do this?
Unhandled rejection TimeoutError: operation timed out
at afterTimeout (/home/ubuntu/workspace/node_modules/bluebird/js/release/timers.js:46:19)
at Timeout.timeoutTimeout [as _onTimeout] (/home/ubuntu/workspace/node_modules/bluebird/js/release/timers.js:76:13)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
let fetchbase = [];
for (var i = 0; i < res.length; ++i) {
fetchbase.push(insertDB('INSERT INTO city SET ?', res[i]));
};
return Promise.all(fetchbase);
let insertDB = (sql,arr) => {
return new Promise(function(resolve, reject) {
Db.getPool().then(function(connection){
connection.query(sql,arr,function(err,result) {
if (err) {
throw err;
console.log(err);
};
console.log(result.insertId);
resolve(result.insertId);
});
});
});
}
item: Promise { [] }
.then(fp.mapValues(fp.toArray))
works...
Basically was hoping Promise.map().then() would run after all the mapped promises, however the then is running immediately.
https://gist.github.com/bag-man/4b5db93b3c9c5e38876946d36c89331f#file-import-js-L32-L45
resultSet.map( item => {
Promise.coroutine( function* (user) {
let opt = {
TableName: 'tableName',
KeyConditions: {
username: {
AttributeValueList: [user],
ComparisonOperator: 'EQ'
}
},
ProjectionExpression: 'firstname, lastname',
}
let userFriends = yield dynamodb.queryAsync(opt)
/* random code here to assign first name and last name to item */
})(item);
return item
});