Created
April 16, 2013 02:47
-
-
Save sonygod/5392964 to your computer and use it in GitHub Desktop.
test nodevm in async excute
This file contains hidden or 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
| package ; | |
| import js.Node; | |
| import async.Build; | |
| import org.transition9.async.Step; | |
| /** | |
| * ... | |
| * test nodevm in async excute | |
| * @author sonygod | |
| */ | |
| class Nodevm implements Build | |
| { | |
| public function new() | |
| { | |
| var offer = {title:'fdsfds',price:323,value:150}; | |
| var initSandbox = { | |
| http: 123, | |
| offer: offer, | |
| done : function(offer) { | |
| trace('sanbox done!'+offer.value); | |
| }, | |
| setTimeout: Node.setTimeout, | |
| say:say | |
| }; | |
| var vm2 :NodeVM = Node.require("vm"); | |
| var fs = Node.fs; | |
| var context2 = vm2.createContext(initSandbox); | |
| // fs.readFile('bitmapdata2.js', NodeC.UTF8, function (err, content) { trace("async start"); vm2.runInThisContext(content); } ); | |
| var step = new Step(); | |
| step.chain([ | |
| function () { | |
| fs.readFile('bitmapdata2.js', NodeC.UTF8, step.cb); | |
| }, | |
| function (err, content:String) { | |
| doFooParallel(vm2, content, step.cb); | |
| trace("end?"); | |
| }, | |
| function (err,?content) { | |
| trace("finish!"); | |
| } | |
| ]); | |
| } | |
| @async(var b:Bool) static function doFooParallel(vm:NodeVM, content:String) { | |
| trace("async vm2.runInThisContext start"); | |
| vm.runInThisContext(content); | |
| return true; | |
| } | |
| function say(value:String):Void { | |
| trace("say:"+value); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment