diff --git a/lib/log.js b/lib/log.js index 9ea5562e1..7de6badb8 100644 --- a/lib/log.js +++ b/lib/log.js @@ -13,9 +13,11 @@ var messageTemplate = function (type, time, tag, info) { return JSON.stringify([type.toUpperCase(), time, tag, info]); }; +var noop = function () {}; + var write = function (ctx, content) { if (!ctx.store) { return; } - ctx.store.log(ctx.channelName, content); + ctx.store.log(ctx.channelName, content, noop); }; // various degrees of logging diff --git a/storage/file.js b/storage/file.js index b14ec4b13..8ccfae079 100644 --- a/storage/file.js +++ b/storage/file.js @@ -816,24 +816,13 @@ var getChannel = function ( // write a message to the disk as raw bytes const messageBin = (env, chanName, msgBin, cb) => { + var complete = Util.once(cb); getChannel(env, chanName, function (err, chan) { - if (!chan) { - cb(err); - return; - } - let called = false; - var complete = function (err) { - if (called) { return; } - called = true; - cb(err); - }; + if (!chan) { return void complete(err); } chan.onError.push(complete); chan.writeStream.write(msgBin, function () { - /*::if (!chan) { throw new Error("Flow unreachable"); }*/ - // TODO replace ad hoc queuing with WriteQueue chan.onError.splice(chan.onError.indexOf(complete), 1); chan.atime = +new Date(); - if (!cb) { return; } complete(); }); });