Skip to content

Instantly share code, notes, and snippets.

@chadwhitacre
Forked from geNAZt/async-context.js
Last active December 12, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadwhitacre/4772851 to your computer and use it in GitHub Desktop.
Save chadwhitacre/4772851 to your computer and use it in GitHub Desktop.
var q = require('q'),
vm = require('vm'),
ctx = vm.createContext({setTimeout: setTimeout, console: console, end: q.defer()}),
script = vm.createScript("now = 1; setTimeout(function() { now = 2; console.log('Inside the VM: ' + now); end.resolve() }, 1000);");
script.runInContext(ctx);
ctx.end.promise.then(function () {
console.log("Now process template with " + ctx.now);
}, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment