Skip to content

Instantly share code, notes, and snippets.

@robinduckett
Created July 20, 2010 10:17
Show Gist options
  • Save robinduckett/482773 to your computer and use it in GitHub Desktop.
Save robinduckett/482773 to your computer and use it in GitHub Desktop.
var Script = process.binding('evals').Script;
Script.runInNewContext('setTimeout(function() {sys.puts(\'2 seconds\')}, 2000);', {sys: require('sys'), setTimeout: setTimeout});
var sandbox = {setTimeout: setTimeout, callback: function(output) {
require('sys').puts('Output: ' + output);
}};
Script.runInNewContext('setTimeout(function() {callback.call(this, \'2 more seconds\');}, 2000);', sandbox);
@FrankGrimm
Copy link

var Script = process.binding('evals').Script;

Script.runInNewContext('setTimeout(function() {sys.puts('2 seconds')}, 2000);', {sys: require('sys'), setTimeout: setTimeout});

var sandbox = {output: '', setTimeout: setTimeout};
setTimeout(
function() {
Script.runInNewContext('output = '2 more seconds';', sandbox);
require('sys').puts(sandbox.output);
}
, 2000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment