Skip to content

Instantly share code, notes, and snippets.

@sonygod
Created April 11, 2013 09:40
Show Gist options
  • Save sonygod/5362041 to your computer and use it in GitHub Desktop.
Save sonygod/5362041 to your computer and use it in GitHub Desktop.
haxe async test for nodejs
(function () { "use strict";
var IntIterator = function(min,max) {
this.min = min;
this.max = max;
};
IntIterator.prototype = {
next: function() {
return this.min++;
}
,hasNext: function() {
return this.min < this.max;
}
}
var Main = function() { }
Main.main = function() {
Test.main();
}
var async = {}
async.Build = function() { }
var Test = function() { }
Test.__interfaces__ = [async.Build];
Test.bubblesort = function(array,__cb) {
var swapping = false;
var temp;
var _afterLoop4 = function() {
__cb(null,array);
};
var _loop3 = (function($this) {
var $r;
var _loop31 = null;
_loop31 = function() {
if(!swapping) {
swapping = true;
var _afterLoop1 = function() {
_loop31();
};
var _iter2 = new IntIterator(0,array.length);
var _loop0 = (function($this) {
var $r;
var _loop01 = null;
_loop01 = function() {
if(_iter2.hasNext()) {
var i = _iter2.next();
Test.delay(1,function(__error) {
if(__error == null) {
if(array[i] > array[i + 1]) {
temp = array[i + 1];
array[i + 1] = array[i];
array[i] = temp;
swapping = false;
}
_loop01();
} else __cb(__error,null);
});
} else _afterLoop1();
};
$r = _loop01;
return $r;
}(this));
_loop0();
} else _afterLoop4();
};
$r = _loop31;
return $r;
}(this));
_loop3();
}
Test.asynchronous = function($int,string,__cb) {
Test.bubblesort([1337,1,-465,3.141592653589793,789,69,789,-132,3.141592653589793,465,789,0,27],function(__error,arry) {
if(__error == null) {
console.log(arry);
__cb(null);
} else __cb(__error);
});
}
Test.main = function() {
console.log("start");
Test.asynchronous(10,"string",function(err) {
if(err != null) console.log("Error: " + err);
});
console.log("fuck end here.");
}
Test.delay = function(ms,cb) {
haxe.Timer.delay(function() {
console.log(ms + " passed");
cb(null);
},ms);
}
var haxe = {}
haxe.Timer = function(time_ms) {
var me = this;
this.id = setInterval(function() {
me.run();
},time_ms);
};
haxe.Timer.delay = function(f,time_ms) {
var t = new haxe.Timer(time_ms);
t.run = function() {
t.stop();
f();
};
return t;
}
haxe.Timer.prototype = {
run: function() {
console.log("run");
}
,stop: function() {
if(this.id == null) return;
clearInterval(this.id);
this.id = null;
}
}
Test.__meta__ = { statics : { bubblesort : { async : null}, asynchronous : { async : null}}};
Main.main();
})();
//@ sourceMappingURL=bitmapdata2.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment