I'm current using the Q promise library in a Node/amqp app. I've read that the performance of Q vs libraries like BlueBird or Vow is... not so good.
Unfortunately, I can't figure out how to use BlueBird (or Vow) to replace my current Q usage patterns.
Here's an example:
this.Start = Q(ampq.connect(url, { heartbeat: heartbeat }))
.then((connection) => {
this.Connection = connection;
return Q(connection.createConfirmChannel());
})
.then((channel) => {
this.ConfirmChannel = channel;
channel.on('error', this.handleChannelError);
return true;
});
I should've mentioned - I'm using TypeScript... In this example I'm taking an amqplib promises, and creating a Q promise out of it (because I don't like the amqplib promises). How do I do that with BlueBird or Vow?
Another example is:
public myMethod(): Q.Promise<boolean> {
var ackDeferred = Q.defer<boolean>();
var handleChannelConfirm = (err, ok): void => {
if (err !== null) {
//message nacked!
ackDeferred.resolve(false);
}
else {
//message acked
ackDeferred.resolve(true);
}
}
...some other code here which invokes callback above...
return ackDeferred.promise;
}
How is that pattern implemented?
So my general questions is:
- Are the performance differences I've read about true?
- How do I migrate from Q to BlueBird or Vow, with a focus on those two patterns (but an explanation of using 'then' would be great, too)?