diff --git a/std/haxe/coro/EventLoop.hx b/std/haxe/coro/EventLoop.hx index f88f95fb6e1..b2f13292387 100644 --- a/std/haxe/coro/EventLoop.hx +++ b/std/haxe/coro/EventLoop.hx @@ -1,8 +1,12 @@ package haxe.coro; +#if (target.threaded && !cppia) import sys.thread.EventLoop; - private typedef EventLoopImpl = sys.thread.EventLoop; +#else +import haxe.coro.EventLoopImpl; +private typedef EventLoopImpl = haxe.coro.EventLoopImpl; +#end @:coreApi abstract EventLoop(EventLoopImpl) { public function new() { diff --git a/std/js/_std/haxe/coro/EventLoop.hx b/std/haxe/coro/EventLoopImpl.hx similarity index 88% rename from std/js/_std/haxe/coro/EventLoop.hx rename to std/haxe/coro/EventLoopImpl.hx index 0aad7ade917..5929f955d6b 100644 --- a/std/js/_std/haxe/coro/EventLoop.hx +++ b/std/haxe/coro/EventLoopImpl.hx @@ -188,7 +188,7 @@ private class SimpleEventLoop { } } -private abstract EventHandler(RegularEvent) from RegularEvent to RegularEvent {} +abstract EventHandler(RegularEvent) from RegularEvent to RegularEvent {} private class RegularEvent { public var nextRunTime:Float; @@ -205,33 +205,4 @@ private class RegularEvent { } } -private typedef EventLoopImpl = SimpleEventLoop; - -@:coreApi abstract EventLoop(EventLoopImpl) { - public function new() { - this = new EventLoopImpl(); - } - - public function tick():Bool { - return switch this.progress() { - case Never: - false; - case _: - true; - } - } - - public function run(func:()->Void):Void { - this.run(func); - } - - public function runIn(func:()->Void, ms:Int):Void { - var handle : EventHandler = null; - - handle = this.repeat(() -> { - this.cancel(handle); - - func(); - }, ms); - } -} \ No newline at end of file +typedef EventLoopImpl = SimpleEventLoop; \ No newline at end of file diff --git a/std/haxe/coro/continuations/RacingContinuation.hx b/std/haxe/coro/continuations/RacingContinuation.hx index 20f01eef362..e87aa81e9a8 100644 --- a/std/haxe/coro/continuations/RacingContinuation.hx +++ b/std/haxe/coro/continuations/RacingContinuation.hx @@ -1,6 +1,32 @@ package haxe.coro.continuations; +#if (target.threaded && !cppia) +import sys.thread.Lock; import sys.thread.Mutex; +import sys.thread.Thread; +#else +private class Lock { + public function new() {} + + public inline function release() {} + + public inline function wait(?t:Float) {} +} + +private class Mutex { + public function new() {} + + public inline function acquire() {} + + public inline function release() {} +} + +private class Thread { + public static function create(f:Void->Void) { + f(); + } +} +#end @:coreApi class RacingContinuation implements IContinuation { final _hx_completion:IContinuation; diff --git a/std/js/_std/haxe/coro/continuations/RacingContinuation.hx b/std/js/_std/haxe/coro/continuations/RacingContinuation.hx deleted file mode 100644 index 486af8d775f..00000000000 --- a/std/js/_std/haxe/coro/continuations/RacingContinuation.hx +++ /dev/null @@ -1,47 +0,0 @@ -package haxe.coro.continuations; - -@:coreApi class RacingContinuation implements IContinuation { - final _hx_completion:IContinuation; - - var assigned:Bool; - - var _hx_result:Any; - - var _hx_error:Any; - - public final _hx_context:CoroutineContext; - - public function new(completion:IContinuation) { - _hx_completion = completion; - _hx_context = _hx_completion._hx_context; - _hx_result = null; - _hx_error = null; - assigned = false; - } - - public function resume(result:T, error:Exception):Void { - _hx_context.scheduler.schedule(() -> { - if (assigned) { - _hx_completion.resume(result, error); - } else { - assigned = true; - _hx_result = result; - _hx_error = error; - } - }); - } - - public function getOrThrow():Any { - if (assigned) { - if (_hx_error != null) { - throw _hx_error; - } - - return _hx_result; - } - - assigned = true; - - return haxe.coro.Primitive.suspended; - } -}