Skip to content

Instantly share code, notes, and snippets.

@sonygod
Forked from stroncium/gist:4563919
Created April 11, 2013 15:04
Show Gist options
  • Select an option

  • Save sonygod/5364117 to your computer and use it in GitHub Desktop.

Select an option

Save sonygod/5364117 to your computer and use it in GitHub Desktop.
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