瀏覽代碼

add Coroutine.suspend "magic" method

Dan Korostelev 4 年之前
父節點
當前提交
03c19db1af
共有 1 個文件被更改,包括 15 次插入1 次删除
  1. 15 1
      std/StdTypes.hx

+ 15 - 1
std/StdTypes.hx

@@ -175,4 +175,18 @@ extern interface ArrayAccess<T> {}
 	Coroutine function.
 **/
 @:coreType
-abstract Coroutine<T> {}
+abstract Coroutine<T> {
+	/**
+		Suspend running coroutine and expose the continuation callback
+		for resuming coroutine execution.
+	**/
+	@:coroutine
+	public static extern function suspend<T>(f:(cont:T->Void)->Void):T;
+
+	#if js
+	// TODO: handle this somehow better
+	static function __init__():Void {
+		js.Syntax.code("{0} = {1}", Coroutine.suspend, cast function(f, cont) return _ -> f(cont));
+	}
+	#end
+}