// ravi
unread,Jul 1, 2013, 12:41:59 PM7/1/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to q-con...@googlegroups.com
Howdy all,
I know how to do the below in a long-winded way by creating my own wrapper promise functions around events, but I bet one of you will have a much cleverer or easier way to do it:
I have three modules that emit a “connected” event after successful connection to DBs. I want to wait for all three before I kick off my “main”. One newbie/naive way of doing this is to simply:
===========
Q.all([ db_check(db1), db_check(db2), db_check(db3) ])
.then(… call main, etc …)
.done();
function db_check(db)
{
var dfrd = Q.defer();
db.on(‘connected’, function() { dfrd.resolve(); });
db.on(‘connectfail’, function(err) { dfrd.reject(new Error(err)); });
return(dfrd.promise);
}
===========
Is there a “better” way to do this?
Thank you,
—ravi