* Graceful exit for async STDIO
(code)
| 390 | */ |
| 391 | |
| 392 | function exit (code) { |
| 393 | // flush output for Node.js Windows pipe bug |
| 394 | // https://github.com/joyent/node/issues/6247 is just one bug example |
| 395 | // https://github.com/visionmedia/mocha/issues/333 has a good discussion |
| 396 | function done () { |
| 397 | if (!(draining--)) _exit(code) |
| 398 | } |
| 399 | |
| 400 | var draining = 0 |
| 401 | var streams = [process.stdout, process.stderr] |
| 402 | |
| 403 | exit.exited = true |
| 404 | |
| 405 | streams.forEach(function (stream) { |
| 406 | // submit empty write request and wait for completion |
| 407 | draining += 1 |
| 408 | stream.write('', done) |
| 409 | }) |
| 410 | |
| 411 | done() |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Determine if launched from cmd.exe |