node/test/simple/test-event-emitter-once.js

21 lines
420 B
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08:00
var common = require('../common');
var assert = require('assert');
2010-10-13 04:52:26 +08:00
var events = require('events');
var e = new events.EventEmitter();
var times_hello_emited = 0;
e.once('hello', function(a, b) {
2010-10-13 04:52:26 +08:00
times_hello_emited++;
});
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
2010-10-13 04:52:26 +08:00
process.addListener('exit', function() {
2010-10-13 04:52:26 +08:00
assert.equal(1, times_hello_emited);
});