From dc09ee43d590a6804f1bff968245c95fa9808e26 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Tue, 25 Feb 2025 18:00:42 +0000 Subject: [PATCH] Add support for `Scheduler#postTask` --- .../macrotaskexecutor/MacrotaskExecutor.scala | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/main/scala/org/scalajs/macrotaskexecutor/MacrotaskExecutor.scala b/core/src/main/scala/org/scalajs/macrotaskexecutor/MacrotaskExecutor.scala index f1916bf..0a666de 100644 --- a/core/src/main/scala/org/scalajs/macrotaskexecutor/MacrotaskExecutor.scala +++ b/core/src/main/scala/org/scalajs/macrotaskexecutor/MacrotaskExecutor.scala @@ -43,7 +43,18 @@ object MacrotaskExecutor extends ExecutionContextExecutor { } private[this] val setImmediate: Runnable => Unit = { - if (js.typeOf(js.Dynamic.global.setImmediate) == Undefined) { + if (js.typeOf(js.Dynamic.global.setImmediate) != Undefined) { + { k => + js.Dynamic.global.setImmediate(() => k.run()) + () + } + } else if (js.typeOf(js.Dynamic.global.scheduler) != Undefined + && js.typeOf(js.Dynamic.global.scheduler.postTask) != Undefined) { + { k => + js.Dynamic.global.scheduler.postTask(() => k.run()) + () + } + } else { var nextHandle = 1 val tasksByHandle = (new js.Object).asInstanceOf[TaskMap] var currentlyRunningATask = false @@ -161,11 +172,6 @@ object MacrotaskExecutor extends ExecutionContextExecutor { () } } - } else { - { k => - js.Dynamic.global.setImmediate(() => k.run()) - () - } } }