Last active
December 11, 2015 07:08
-
-
Save stroncium/4563919 to your computer and use it in GitHub Desktop.
haxe async version of test from haxe continuation
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 tests; | |
| import js.Node; | |
| using AsyncLambda; | |
| class TestNode implements async.Build{ | |
| @:async static function writeAll(fd:Int, content:String){ | |
| var total = 0, length = content.length; | |
| while (total > length){ | |
| async(written = Node.fs.write(fd, content, total, length - total, null)); | |
| total+= written; | |
| } | |
| } | |
| @:async static function startTest():Void | |
| { | |
| var files = ["1.txt", "2.log", "3.txt", "4.ini", "5.conf"]; | |
| async( | |
| Node.fs.mkdir("TestNode"), | |
| files.parallelExec(Async.it(function(fileName, cb){ // parallelExec is a lambda extenstion, not a part of lib yet | |
| async( | |
| fd = Node.fs.open("TestNode/" + fileName, "w+"), | |
| writeAll(fd, "Content of " + fileName), | |
| Node.fs.close(fd) | |
| ); | |
| })) | |
| ); | |
| } | |
| public static function main(){ | |
| startTest(function(error){ | |
| if(error != null) trace('Error: '+error); | |
| else trace("Test is done!"); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment