Browse Source

added delayed and delayedArg

Nicolas Cannasse 19 years ago
parent
commit
0faa6efc8b
1 changed files with 21 additions and 0 deletions
  1. 21 0
      std/haxe/Timer.hx

+ 21 - 0
std/haxe/Timer.hx

@@ -57,4 +57,25 @@ class Timer {
 
 	public function run(){
 	}
+
+	public static function delayed( f : Void -> Void, time : Int ) : Void -> Void {
+		return function() {
+			var t = new haxe.Timer(time);
+			t.run = function() {
+				t.stop();
+				f();
+			};
+		};
+	}
+
+	public static function delayedArg<T>( f : T -> Void, time : Int ) : T -> Void {
+		return function(arg) {
+			var t = new haxe.Timer(time);
+			t.run = function() {
+				t.stop();
+				f(arg);
+			};
+		};
+	}
+
 }