var EventEmitter = require('events').EventEmitter

const emitterFactory = function() {
	const emitter = new EventEmitter()

	const realEmit = emitter.emit;
	emitter.emit = function() {
		try {
			realEmit.apply(emitter, arguments)
		} catch (e) {
			console.log("Error while dispatching event: " + e.stack)
		}
	};

	global.fiberWrapperEmitter = emitter

	return emitter
}

module.exports = require('bindings')('fiberWrapper')
module.exports.path = __filename
module.exports.FiberWrapper._internal_setEmitterFactory(emitterFactory)
