2010-12-05 07:20:34 +08:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
2010-01-16 04:46:08 +08:00
|
|
|
var events = require('events');
|
2009-08-25 22:59:06 +08:00
|
|
|
|
2010-01-16 04:46:08 +08:00
|
|
|
var e = new events.EventEmitter();
|
2009-08-25 22:59:06 +08:00
|
|
|
|
|
|
|
var events_new_listener_emited = [];
|
|
|
|
var times_hello_emited = 0;
|
|
|
|
|
2010-12-06 03:15:30 +08:00
|
|
|
e.addListener('newListener', function(event, listener) {
|
|
|
|
console.log('newListener: ' + event);
|
2009-08-27 00:22:00 +08:00
|
|
|
events_new_listener_emited.push(event);
|
|
|
|
});
|
|
|
|
|
2010-12-06 03:15:30 +08:00
|
|
|
e.on('hello', function(a, b) {
|
|
|
|
console.log('hello');
|
|
|
|
times_hello_emited += 1;
|
|
|
|
assert.equal('a', a);
|
|
|
|
assert.equal('b', b);
|
2009-08-27 00:22:00 +08:00
|
|
|
});
|
|
|
|
|
2010-12-06 03:15:30 +08:00
|
|
|
console.log('start');
|
2009-08-27 00:22:00 +08:00
|
|
|
|
2010-12-06 03:15:30 +08:00
|
|
|
e.emit('hello', 'a', 'b');
|
2009-08-25 22:59:06 +08:00
|
|
|
|
2010-12-06 03:15:30 +08:00
|
|
|
process.addListener('exit', function() {
|
|
|
|
assert.deepEqual(['hello'], events_new_listener_emited);
|
2009-11-29 01:26:59 +08:00
|
|
|
assert.equal(1, times_hello_emited);
|
2009-08-27 00:51:04 +08:00
|
|
|
});
|
2009-08-25 22:59:06 +08:00
|
|
|
|
|
|
|
|