You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
970 B
JavaScript

5 months ago
"use strict";
const c = require("colorette");
module.exports = function createDebugStream(label) {
function debugPrint(... values) {
console.debug(`[@promistream/debug][${c.bold(c.cyan(label))}] ${values[0]}`, ... values.slice(1));
}
return {
_promistreamVersion: 0,
description: `map stream`,
abort: function (reason, source) {
debugPrint(`${c.bgRed("abort was requested")}; reason:`, reason);
return source.abort(reason);
},
peek: async function (source) {
debugPrint("read was requested");
let result = source.peek();
debugPrint(`${c.bgBlue("peek result:")}`, result);
return result;
},
read: async function produceValue_debug(source) {
debugPrint("read was requested");
try {
let value = await source.read();
debugPrint(`${c.bgGreen(c.black("seen value:"))}`, value);
return value;
} catch (error) {
debugPrint(`${c.bgRed(c.white("error thrown in read:"))}`, error);
throw error;
}
}
};
};