Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created November 11, 2010 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnoordhuis/673377 to your computer and use it in GitHub Desktop.
Save bnoordhuis/673377 to your computer and use it in GitHub Desktop.
readsync-busy-loop.js
//
// 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