Created
November 11, 2010 22:50
-
-
Save bnoordhuis/673377 to your computer and use it in GitHub Desktop.
readsync-busy-loop.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// test case: fs.readSync() eventually starts busy-looping in C++ land | |
// | |
// create a writer with `while true; do date >> /tmp/time.log; sleep 1; done` | |
// then run `node tail.js /tmp/time.log` | |
// | |
Buffer = require('buffer').Buffer; | |
fs = require('fs'); | |
b = new Buffer(256); | |
fd = fs.openSync(process.argv[2], 'r'); | |
while (true) { | |
console.log('.'); // marker to make sure the loop isn't actually spinning | |
fs.readSync(fd, b, 0, b.length, 0); | |
console.log(b.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment