Skip to content

Instantly share code, notes, and snippets.

/out.txt Secret
Created Jan 2, 2014

Embed
What would you like to do?
[ 'create',
'add',
'add',
'before',
'go',
'before',
'done',
'after',
'after' ]
ok
var common = require('../common');
var EventEmitter = require('events').EventEmitter;
var assert = require('assert');
var handler_log = [];
var handlers = {
create: function () {
handler_log.push('create');
},
before: function () {
handler_log.push('before');
},
after: function () {
handler_log.push('after');
},
error: function () {
handler_log.push('error');
},
add: function () {
handler_log.push('add');
},
remove: function () {
handler_log.push('remove');
}
};
var observer = EventEmitter.addObserver(handlers);
var ee = new EventEmitter();
EventEmitter.removeObserver(observer);
ee.on('done', function () {
// this event should run without observers
handler_log.push('done');
});
ee.on('go', function () {
handler_log.push('go');
ee.emit('done');
});
ee.emit('go');
console.log(handler_log);
console.log('ok');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.