I have a class that has a maintains an instance variable called write_stream. This write_stream variable gets updated with new write streams and currently I do something like this:
const fs = require('fs');
class Test {
constructor() {
this.write_stream = null;
}
...
set_write_stream(new_file_path) {
if (this.write_stream != null) {
this.write_stream.end();
}
this.write_stream = fs.createWriteStream(new_file_path);
}
}
Is this an acceptable way to do this? Is there a better way to do it? Is stream.end() synchronous, or do I need to wait for some sort of promise before continuing onto fs.createWriteStream()?