Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Responding with the correct callback #33

Open
wants to merge 4 commits into from

2 participants

tanguylebarzic Marak
tanguylebarzic

When the messages are queued, the callbacks called once they are sent should be the ones given as argument for each email, not the one of the last email.

tanguylebarzic

(I agree it seldom happens, just in case).

Regards,

Tanguy

Marak
Owner

I think this makes a lot of sense. Let me do a sanity check for review and we'll merge.

Thank you!

tanguylebarzic

Hi,

I added another small fix : if a file was missing, the first time the method was called the callback would be called with the proper error, but the next times, it would never be called.

Another way of fixing it would be to set _templateCache[message.template].error to the error raised, and to respond this for each new call to the method (ie. without having to call readFile each time), but it would mean the server has to be reloaded when the missing file is eventually added, which I didn't like personally.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 8, 2011
  1. tanguylebarzic
  2. tanguylebarzic

    A bit proper

    tanguylebarzic authored
Commits on Jul 10, 2011
  1. tanguylebarzic
  2. tanguylebarzic

    Formatting

    tanguylebarzic authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/node_mailer.js
10 lib/node_mailer.js
View
@@ -119,7 +119,7 @@ exports.send = function node_mail(message, callback) {
}
else {
// We've started to load the template, but it's not loaded yet. queue up this message to be sent later
- _templateCache[message.template].queue.push(message);
+ _templateCache[message.template].queue.push({message: message, callback: callback});
}
}
else {
@@ -131,6 +131,7 @@ exports.send = function node_mail(message, callback) {
fs.readFile(message.template, function(err, result){
if (err) {
+ _templateCache[message.template] = false;
callback(err);
return;
}
@@ -139,8 +140,11 @@ exports.send = function node_mail(message, callback) {
_templateCache[message.template].loaded = true;
// "Drain" the queue
- _templateCache[message.template].queue.push(message);
- _templateCache[message.template].queue.forEach(function(msg, i){
+ _templateCache[message.template].queue.push({message: message, callback: callback});
+ _templateCache[message.template].queue.forEach(function(queuedItem, i){
+ var msg = queuedItem.message;
+ var callback = queuedItem.callback;
+
msg.html = mustache.to_html(_templateCache[message.template].template, msg.data);
pool.send(new EmailMessage(merge(msg,{
to: msg.to,
Something went wrong with that request. Please try again.