title: Is stream.end() synchronous?
body: <p>I have a class that has a maintains an instance variable called <code>write_stream</code>. This <code>write_stream</code> variable gets updated with new write streams and currently I do something like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>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);
     }
  }
  </code></pre>
  
  <p>Is this an acceptable way to do this? Is there a better way to do it? Is <code>stream.end()</code> synchronous, or do I need to wait for some sort of promise before continuing onto <code>fs.createWriteStream()</code>?</p>