jashkenas/coffee-script — pull request #1944 by TrevorBurnham (2011-12-18 19:10:13+00:00)
Title: Misc fixes for --watch

So, the `fs.watch` API has a problem that forces us to get a little messy: If you try to `fs.watch` a nonexistent file, an error will be thrown. There's no "async" version of `fs.watch`. Since there's always a chance that a file will be deleted between a `path.exists` or `fs.stats` call and an `fs.watch` inside of it (in fact, in tests I found that this happened frequently when using tools like git), the only safe fix is to catch those `ENOENT` errors and handle them properly. That's the main thing this patch does.

The other thing is that it wraps watched file compilation in a timeout that gets reset if the file is modified again within 25ms. That's small enough that the delay shouldn't be noticeable, but large enough to get rid of those annoying duplicate

compiled foo.coffee
compiled foo.coffee

messages that happen when a tool blanks the file to 0 length before overwriting it.