veged/coa — Issue #14: Postpone `process.exit()` call to 'natural' node.js exit stage
Author: arikon
Created: 2011-12-21 19:47:23+00:00
State: open

Demo of problem, see comment inside code block:

```js

var FS = require('fs'),
output = process.stdout
data = getData();

output = FS.createWriteStream('exit-test.txt');

output.on('end', function() {
console.log('output stream end');
});

output.write(data);
if (output !== process.stdout) output.end();

process.once('exit', function(code) {
code = code || 0;
console.log('about to exit with code %s', code);
process.exit(code);
});

// Uncomment, and exit-test.txt wiil be empty
//process.exit(1);

function getData() {
var data = '';
for (var i = 0; i < 5000000; i++) {
data += 'a';
}
return data;
}
```