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()) - () - } } }