File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
main/scala/org/scalajs/macrotaskexecutor
test/scala/org/scalajs/macrotaskexecutor Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,20 @@ object MacrotaskExecutor extends ExecutionContextExecutor {
134134 channel.port2.postMessage(handle)
135135 ()
136136 }
137+ } else if (
138+ js.typeOf(
139+ js.Dynamic .global.navigator
140+ ) != Undefined && js.Dynamic .global.navigator.userAgent
141+ .asInstanceOf [js.UndefOr [String ]]
142+ .exists(_.contains(" jsdom" ))
143+ ) {
144+ val setImmediate =
145+ js.Dynamic .global.Node .constructor(" return setImmediate" )()
146+
147+ { k =>
148+ setImmediate(k)
149+ ()
150+ }
137151 } else {
138152 // we don't try to look for process.nextTick since scalajs doesn't support old node
139153 // we're also not going to bother fast-pathing for IE6; just fall through
Original file line number Diff line number Diff line change @@ -32,15 +32,15 @@ class MacrotaskExecutorSuite extends FunSuite {
3232 else
3333 Future .unit.flatMap(_ => loop(n - 1 )).map(_ + 1 )
3434
35- // val start = System.currentTimeMillis()
36- // val MinimumClamp = 10000 * 2 * 4 // HTML5 specifies a 4ms clamp (https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setTimeout#Minimum.2F_maximum_delay_and_timeout_nesting)
35+ val start = System .currentTimeMillis()
36+ val MinimumClamp = 10000 * 2 * 4 // HTML5 specifies a 4ms clamp (https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setTimeout#Minimum.2F_maximum_delay_and_timeout_nesting)
3737
3838 loop(10000 ) flatMap { res =>
3939 Future {
40- // val end = System.currentTimeMillis()
40+ val end = System .currentTimeMillis()
4141
4242 assert(res == 10000 )
43- // assert((end - start).toDouble / MinimumClamp < 0.25) // we should beat the clamping by at least 4x even on slow environments
43+ assert((end - start).toDouble / MinimumClamp < 0.25 ) // we should beat the clamping by at least 4x even on slow environments
4444 }
4545 }
4646 }
You can’t perform that action at this time.
0 commit comments