From c5de4164bca50e2a44d2c95374ac42e248f527c5 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 21 Aug 2019 13:49:39 +0200 Subject: [PATCH] make sure getIndex is always async in historyKeeper --- historyKeeper.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/historyKeeper.js b/historyKeeper.js index 672f63b76..e81b00f5b 100644 --- a/historyKeeper.js +++ b/historyKeeper.js @@ -221,7 +221,12 @@ module.exports.create = function (cfg) { */ const getIndex = (ctx, channelName, cb) => { const chan = ctx.channels[channelName]; - if (chan && chan.index) { return void cb(undefined, chan.index); } + if (chan && chan.index) { + // enforce async behaviour + return void setTimeout(function () { + cb(undefined, chan.index); + }); + } computeIndex(channelName, (err, ret) => { if (err) { return void cb(err); } if (chan) { chan.index = ret; }