Created
April 11, 2013 08:52
-
-
Save sonygod/5361832 to your computer and use it in GitHub Desktop.
hx-async test
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 ; | |
/** | |
* ... | |
* @author sonygod | |
*/ | |
import async.Build; | |
import async.Async; | |
class Test implements Build | |
{ | |
@async(var ret: Array<Float>) static function bubblesort(array : Array<Float>) { | |
var swapping = false; | |
var temp : Float; | |
while (!swapping) { | |
swapping = true; | |
for (i in 0...array.length) { | |
[] = delay(10); | |
if (array[i] > array[i+1]) { | |
temp = array[i+1]; | |
array[i+1] = array[i]; | |
array[i] = temp; | |
swapping = false; | |
} | |
} | |
} | |
return array; | |
} | |
@async static function asynchronous(int:Int, string:String){ | |
var arry:Array<Float>; | |
[arry] = bubblesort([1337, 1, -465, 3.141592653589793, 789, 69, 789, -132, 3.141592653589793, 465, 789, 0, 27]); | |
trace(arry); | |
} | |
public static function main() { | |
trace("start"); | |
asynchronous(10, 'string', function(err){ | |
if(err != null){ | |
trace('Error: '+err); | |
} | |
}); | |
} | |
static inline function delay(ms:Int, cb){ | |
platformDelay(ms, function(){ trace(ms+' passed'); cb(null); }); | |
} | |
static inline function platformDelay(ms:Int, fun){ | |
#if (cpp || neko || php) fun(); #else haxe.Timer.delay(fun, ms); #end | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment