always supply a callback when writing messages
This commit is contained in:
parent
e5cea3c250
commit
cb6b4a8eb3
@ -13,9 +13,11 @@ var messageTemplate = function (type, time, tag, info) {
|
|||||||
return JSON.stringify([type.toUpperCase(), time, tag, info]);
|
return JSON.stringify([type.toUpperCase(), time, tag, info]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var noop = function () {};
|
||||||
|
|
||||||
var write = function (ctx, content) {
|
var write = function (ctx, content) {
|
||||||
if (!ctx.store) { return; }
|
if (!ctx.store) { return; }
|
||||||
ctx.store.log(ctx.channelName, content);
|
ctx.store.log(ctx.channelName, content, noop);
|
||||||
};
|
};
|
||||||
|
|
||||||
// various degrees of logging
|
// various degrees of logging
|
||||||
|
|||||||
@ -816,24 +816,13 @@ var getChannel = function (
|
|||||||
|
|
||||||
// write a message to the disk as raw bytes
|
// write a message to the disk as raw bytes
|
||||||
const messageBin = (env, chanName, msgBin, cb) => {
|
const messageBin = (env, chanName, msgBin, cb) => {
|
||||||
|
var complete = Util.once(cb);
|
||||||
getChannel(env, chanName, function (err, chan) {
|
getChannel(env, chanName, function (err, chan) {
|
||||||
if (!chan) {
|
if (!chan) { return void complete(err); }
|
||||||
cb(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let called = false;
|
|
||||||
var complete = function (err) {
|
|
||||||
if (called) { return; }
|
|
||||||
called = true;
|
|
||||||
cb(err);
|
|
||||||
};
|
|
||||||
chan.onError.push(complete);
|
chan.onError.push(complete);
|
||||||
chan.writeStream.write(msgBin, function () {
|
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.onError.splice(chan.onError.indexOf(complete), 1);
|
||||||
chan.atime = +new Date();
|
chan.atime = +new Date();
|
||||||
if (!cb) { return; }
|
|
||||||
complete();
|
complete();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user