paulmillr/chokidar — pull request #130 by chrisdickinson (2014-06-13 07:40:56+00:00)
Title: Close ignores further events

There was a slight race condition in `_handle` -- the method has two async steps (realpath & stat), and before completion of either of those steps, the FSWatch instance may have been closed.

Previously, even though the watcher was closed, new listeners would be added and chokidar would thus keep the process alive. This behavior has been rectified.

The sequence of events would be something like the following:

```
_handle
calls realpath
close <----------
realpath complete
stat
stat complete

```

This solves problems for libraries using chokidar -- it prevents tests from occasionally hanging, despite closing their FSWatch instances.