joyent/node — pull request #6503 by timrwood (2013-11-12 20:23:13+00:00)
Title: events: don't call once twice

Emitting an event within a `EventEmitter#once` callback of the same event name will cause subsequent `EventEmitter#once` listeners of the same name to be called multiple times.

```js
var events = require('events');
var emitter = new events.EventEmitter();

emitter.once('e', function () {
emitter.emit('e');
console.log(1);
});

emitter.once('e', function () {
console.log(2);
});

emitter.emit('e');

// Output
// 2
// 1
// 2
```

This fixes the issue, only calling the listener method if it was not already called.

A real world example of this happening is at https://github.com/yeoman/generator/pull/402.