Hello,
I'm not sure if I am missing some important API documentation, or am just doing something wrong, but I ran into the following issue when upgrading to streamline 1.x / ez-streams 1.2 (which I tried to do simultaneously).
The following program, which is supposed to write some lines to a file, typically exits without having written anything to the file (leaving a file of length 0).
#!/usr/bin/env _node
var ez = require('ez-streams');
function main(_) {
var outputFile = ez.devices.file.text.writer('testoutput.txt');
var i;
for (i = 0; i < 100; ++i) {
outputFile.write(_, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'utf-8');
outputFile.write(_, '\n', 'utf-8');
}
outputFile.write(_, undefined); // Not sure if this is needed, but it doesn't work without this, either
outputFile.end();
}
main(function (err) {
if (err) {
console.error(err.stack);
process.exit(1);
}
process.exit();
});
This is on:
* streamline 1.0.13
* ez-streams 1.2.1
* streamline-runtime 1.0.16
I presume it's a race condition between the flushing of the stream data and the exit of the program, because if I add a setTimeout(_, 1000) after the call to end(), the data is written.
In the past, under streamline 0.10.17 and ez-streams 0.1.7, what I did was to invoke end() with a callback:
which seems to cause the data to be flushed reliably. But this method no longer takes a callback argument. Can you recommend how in general I can wait to ensure that the data has been flushed?
Thanks in advance for your help,
Phil Sung