implement callback for getMessages

pull/1/head
ansuz 9 years ago
parent a527024a8c
commit ce69062b7c

@ -38,7 +38,7 @@ var insert = function (db, channelName, content, cb) {
} }
}; };
var getMessages = function (db, channelName, msgHandler) { var getMessages = function (db, channelName, msgHandler, cb) {
var index; var index;
nThen(function (waitFor) { nThen(function (waitFor) {
getIndex(db, channelName, waitFor(function (i) { index = i; })); getIndex(db, channelName, waitFor(function (i) { index = i; }));
@ -48,6 +48,7 @@ var getMessages = function (db, channelName, msgHandler) {
if (e) { throw e; } if (e) { throw e; }
msgHandler(out); msgHandler(out);
if (i < index) { again(i+1); } if (i < index) { again(i+1); }
else if (cb) { cb(); }
})); }));
}; };
if (index > -1) { again(0); } if (index > -1) { again(0); }
@ -62,8 +63,8 @@ module.exports.create = function (conf, cb) {
message: function (channelName, content, cb) { message: function (channelName, content, cb) {
insert(db, channelName, content, cb); insert(db, channelName, content, cb);
}, },
getMessages: function (channelName, msgHandler) { getMessages: function (channelName, msgHandler, cb) {
getMessages(db, channelName, msgHandler); getMessages(db, channelName, msgHandler, cb);
} }
}); });
}; };

Loading…
Cancel
Save