I'm going to create a node repl that works within a node.
The run function is a function that returns the output value when the code to be put in the repl is passed over to the factor.
Is there a way to transfer data from a write function to a run function while the run function is running?
const repl = require('repl');
const { Readable, Writable } = require('stream');
const readable = new Readable({
read(size) {
return true;
}
});
const writable = new Writable({
write(chunk, encoding, callback) {
const value = chunk.toString();
if (value === "") {
// todo : send data to function run
} else {
// todo : stack data for function run
}
console.log(chunk);
callback();
}
});
repl.start({
prompt: "",
input: readable,
output: writable
});
async function run(code) {
readable.push(code);
// todo
}
run("setTimeout(() => {console.log('test')}, 1000);\n");
exports.run = run;