2010-03-09 07:06:29 +08:00
|
|
|
require("../common");
|
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;
|
|
|
|
|
2009-08-27 00:22:00 +08:00
|
|
|
e.addListener("newListener", function (event, listener) {
|
2010-06-24 08:40:51 +08:00
|
|
|
console.log("newListener: " + event);
|
2009-08-27 00:22:00 +08:00
|
|
|
events_new_listener_emited.push(event);
|
|
|
|
});
|
|
|
|
|
|
|
|
e.addListener("hello", function (a, b) {
|
2010-06-24 08:40:51 +08:00
|
|
|
console.log("hello");
|
2009-08-27 00:22:00 +08:00
|
|
|
times_hello_emited += 1
|
2009-11-29 01:26:59 +08:00
|
|
|
assert.equal("a", a);
|
|
|
|
assert.equal("b", b);
|
2009-08-27 00:22:00 +08:00
|
|
|
});
|
|
|
|
|
2010-06-24 08:40:51 +08:00
|
|
|
console.log("start");
|
2009-08-27 00:22:00 +08:00
|
|
|
|
2009-09-12 19:01:03 +08:00
|
|
|
e.emit("hello", "a", "b");
|
2009-08-25 22:59:06 +08:00
|
|
|
|
2009-08-27 00:51:04 +08:00
|
|
|
process.addListener("exit", function () {
|
2009-11-29 01:26:59 +08:00
|
|
|
assert.deepEqual(["hello"], events_new_listener_emited);
|
|
|
|
assert.equal(1, times_hello_emited);
|
2009-08-27 00:51:04 +08:00
|
|
|
});
|
2009-08-25 22:59:06 +08:00
|
|
|
|
|
|
|
|