Skip to content

Instantly share code, notes, and snippets.

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;
var vm = require('vm'),
code = 'var square = n * n;',
fn = new Function('n', code),
script = vm.createScript(code),
sandbox;
n = 5;
sandbox = { n: n };
benchmark = function(title, funk) {
abstract FunctionReturning<T>(Dynamic) {
inline function new (x:Dynamic) this = x;
@:from static inline function from0 <T>(x:Void->T):FunctionReturning<T> return new FunctionReturning(x);
@:from static inline function from1 <T>(x:Dynamic->T):FunctionReturning<T> return new FunctionReturning(x);
@:from static inline function from2 <T>(x:Dynamic->Dynamic->T):FunctionReturning<T> return new FunctionReturning(x);
@:from static inline function from3 <T>(x:Dynamic->Dynamic->Dynamic->T):FunctionReturning<T> return new FunctionReturning(x);
/* ... */
}
class Test {