bruce/node-temp — pull request #6 by ryangreenberg (2012-01-01 20:12:36+00:00)
Title: Use single exit callback

This diff solves the same problem that bermi addressed https://github.com/bruce/node-temp/pull/3, which is that if you create more than 10 temp files or dirs, you get the following warning:

```
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at EventEmitter. (events.js:133:17)
at EventEmitter. (node.js:383:29)
at /Users/ryangreenberg/workspace/node-temp/lib/temp.js:73:13
at /Users/ryangreenberg/workspace/node-temp/lib/temp.js:62:3
at Object.openSync (/Users/ryangreenberg/workspace/node-temp/lib/temp.js:125:3)
at Object. (/Users/ryangreenberg/workspace/node-temp/test/temp-test.js:45:8)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
```

The advantage of bermi's fix is that it's shorter.

A couple advantages of the attached diff:

- a listener to process exit is only created when temp files are created (as opposed to unconditionally when you require the module)
- named functions may make it more explicit what is happening for someone reading the code
- includes a test that ensures that a single listener is used for all exit events.
- you could expose deleteAllTempFiles in exports if people wanted an interface to deleting all temp files before process exit.

I didn't change the version number, so please change it if you accept this request. Thanks!