always supply a callback when writing messages

pull/1/head
ansuz 5 years ago
parent e5cea3c250
commit cb6b4a8eb3

@ -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

@ -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();
});
});

Loading…
Cancel
Save