Skip to content

Commit dc09ee4

Browse files
committed
Add support for Scheduler#postTask
1 parent cf9d18f commit dc09ee4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

core/src/main/scala/org/scalajs/macrotaskexecutor/MacrotaskExecutor.scala

+12-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ object MacrotaskExecutor extends ExecutionContextExecutor {
4343
}
4444

4545
private[this] val setImmediate: Runnable => Unit = {
46-
if (js.typeOf(js.Dynamic.global.setImmediate) == Undefined) {
46+
if (js.typeOf(js.Dynamic.global.setImmediate) != Undefined) {
47+
{ k =>
48+
js.Dynamic.global.setImmediate(() => k.run())
49+
()
50+
}
51+
} else if (js.typeOf(js.Dynamic.global.scheduler) != Undefined
52+
&& js.typeOf(js.Dynamic.global.scheduler.postTask) != Undefined) {
53+
{ k =>
54+
js.Dynamic.global.scheduler.postTask(() => k.run())
55+
()
56+
}
57+
} else {
4758
var nextHandle = 1
4859
val tasksByHandle = (new js.Object).asInstanceOf[TaskMap]
4960
var currentlyRunningATask = false
@@ -161,11 +172,6 @@ object MacrotaskExecutor extends ExecutionContextExecutor {
161172
()
162173
}
163174
}
164-
} else {
165-
{ k =>
166-
js.Dynamic.global.setImmediate(() => k.run())
167-
()
168-
}
169175
}
170176
}
171177

0 commit comments

Comments
 (0)