Let's assume I run one JS file with the following code:
function* naturalsGenerator(){
let num = 0;
while(true){
yield num++;
}
}
const naturals = naturalsGenerator();
console.log(naturals.next().value); // prints 0
writeInAFile(naturals,"file.bin");
And then I run the following script:
const deserializedGenerator = readFromFile("file.bin");
console.log(deserializedGenerator.next().value); //prints 1
Is there any way to implement writeInFile and readFromFile functions, in node.js or any other js engine?