mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
824 B
45 lines
824 B
14 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
14 years ago
|
var events = require('events');
|
||
|
|
||
|
var e = new events.EventEmitter();
|
||
|
var times_hello_emited = 0;
|
||
|
|
||
14 years ago
|
e.once('hello', function(a, b) {
|
||
14 years ago
|
times_hello_emited++;
|
||
|
});
|
||
|
|
||
14 years ago
|
e.emit('hello', 'a', 'b');
|
||
|
e.emit('hello', 'a', 'b');
|
||
|
e.emit('hello', 'a', 'b');
|
||
|
e.emit('hello', 'a', 'b');
|
||
14 years ago
|
|
||
14 years ago
|
var remove = function() {
|
||
13 years ago
|
assert.fail(1, 0, 'once->foo should not be emitted', '!');
|
||
14 years ago
|
};
|
||
|
|
||
|
e.once('foo', remove);
|
||
|
e.removeListener('foo', remove);
|
||
|
e.emit('foo');
|
||
|
|
||
13 years ago
|
process.on('exit', function() {
|
||
14 years ago
|
assert.equal(1, times_hello_emited);
|
||
|
});
|
||
|
|
||
11 years ago
|
var times_recurse_emitted = 0;
|
||
|
|
||
|
e.once('e', function() {
|
||
|
e.emit('e');
|
||
|
times_recurse_emitted++;
|
||
|
});
|
||
|
|
||
|
e.once('e', function() {
|
||
|
times_recurse_emitted++;
|
||
|
});
|
||
|
|
||
|
e.emit('e');
|
||
|
|
||
|
process.on('exit', function() {
|
||
|
assert.equal(2, times_recurse_emitted);
|
||
|
});
|