瀏覽代碼

somehow make suspend work on JVM

Simon Krajewski 1 年之前
父節點
當前提交
fb857ab477
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 9 0
      std/StdTypes.hx
  2. 1 1
      tests/misc/coroutines/src/Main.hx

+ 9 - 0
std/StdTypes.hx

@@ -181,8 +181,17 @@ abstract Coroutine<T:haxe.Constraints.Function> {
 		for resuming coroutine execution.
 	**/
 	@:coroutine
+	#if jvm overload #end
 	public static extern function suspend<T>(f:(cont:(T, Null<Dynamic>) -> Void)->Void):T;
 
+	#if jvm
+	@:native("suspend")
+	@:ifFeature("_StdTypes.Coroutine_Impl_.suspend")
+	static function nativeSuspend<T>(f, cont:(T, Null<Dynamic>) -> Void) {
+		return (_, _) -> f(cont);
+	}
+	#end
+
 	#if js // TODO: implement this all properly for all the targets
 	static function __init__():Void {
 		js.Syntax.code("{0} = {1}", Coroutine.suspend, cast function(f, cont) return (_, _) -> f(cont));

+ 1 - 1
tests/misc/coroutines/src/Main.hx

@@ -2,8 +2,8 @@ function main() {
 	utest.UTest.run([
 		new TestBasic(),
 		new TestControlFlow(),
-		#if js
 		new TestGenerator(),
+		#if js
 		new TestJsPromise(),
 		#end
 	]);