wait for all streams to finish - stream a directory of files
<p>I'm using <a href="https://github.com/pkgcloud/pkgcloud/blob/master/docs/providers/rackspace/storage.md#clientuploadoptions" rel="nofollow noreferrer">client.upload</a> in <a href="https://github.com/pkgcloud/pkgcloud" rel="nofollow noreferrer">pkgcloud</a> to upload a directory of files. How can I execute a callback after all the streams have finished? Is there a built-in way to register each stream's &quot;finish&quot; event and execute a callback after they have all fired?</p>
<pre><code>var filesToUpload = fs.readdirSync(&quot;./local_path&quot;); // will make this async

for(let file of filesToUpload) {
    var writeStream = client.upload({
        container: &quot;mycontainer&quot;,
        remote: file
    });
    // seems like I should register finish events with something
    writeStream.on(&quot;finish&quot;, registerThisWithSomething);
    fs.createReadStream(&quot;./local_path/&quot; + file).pipe(writeStream);
}
</code></pre>