浏览代码

added delayed and delayedArg

Nicolas Cannasse 19 年之前
父节点
当前提交
0faa6efc8b
共有 1 个文件被更改,包括 21 次插入0 次删除
  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);
+			};
+		};
+	}
+
 }