From ce69062b7cf156c87bf8e4a3f1d704d4035b44f8 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 21 Apr 2016 17:01:21 +0200 Subject: [PATCH] implement callback for getMessages --- storage/lvl.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/storage/lvl.js b/storage/lvl.js index 0f233178e..0f3954968 100644 --- a/storage/lvl.js +++ b/storage/lvl.js @@ -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; nThen(function (waitFor) { getIndex(db, channelName, waitFor(function (i) { index = i; })); @@ -48,6 +48,7 @@ var getMessages = function (db, channelName, msgHandler) { if (e) { throw e; } msgHandler(out); if (i < index) { again(i+1); } + else if (cb) { cb(); } })); }; if (index > -1) { again(0); } @@ -62,8 +63,8 @@ module.exports.create = function (conf, cb) { message: function (channelName, content, cb) { insert(db, channelName, content, cb); }, - getMessages: function (channelName, msgHandler) { - getMessages(db, channelName, msgHandler); + getMessages: function (channelName, msgHandler, cb) { + getMessages(db, channelName, msgHandler, cb); } }); };