Created
December 10, 2011 17:12
-
-
Save rehanift/1455618 to your computer and use it in GitHub Desktop.
Node VM waiting for event listeners to fire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vm = require("vm"), | |
util = require("util"), | |
events = require("events"); | |
var fooClass = function(){}; | |
util.inherits(fooClass, events.EventEmitter); | |
fooClass.prototype.run = function(){ | |
this.emit('myevent', "Hello!"); | |
}; | |
var context = { | |
Foo: fooClass, | |
console: console | |
}; | |
var code = "var foo = new Foo(); foo.on('myevent', function(data){ console.log(data); }); foo.run();"; | |
vm.runInNewContext(code, context); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment