diff --git a/core/js/src/main/scala/cats/effect/unsafe/BatchingMacrotaskExecutor.scala b/core/js/src/main/scala/cats/effect/unsafe/BatchingMacrotaskExecutor.scala index fe4ebe992e..4b41fc6f5b 100644 --- a/core/js/src/main/scala/cats/effect/unsafe/BatchingMacrotaskExecutor.scala +++ b/core/js/src/main/scala/cats/effect/unsafe/BatchingMacrotaskExecutor.scala @@ -56,7 +56,7 @@ private[effect] final class BatchingMacrotaskExecutor( private[this] var needsReschedule = true private[this] val fibers = new JSArrayQueue[IOFiber[_]] - private[this] object executeBatchTask extends Runnable { + private[this] object executeBatchTaskRunnable extends Runnable { def run() = { // do up to batchSize tasks var i = 0 @@ -85,6 +85,9 @@ private[effect] final class BatchingMacrotaskExecutor( } } + private[this] val executeBatchTaskJSFunction: js.Function0[Any] = + () => executeBatchTaskRunnable.run() + /** * Execute the `runnable` in the next iteration of the event loop. */ @@ -106,7 +109,7 @@ private[effect] final class BatchingMacrotaskExecutor( needsReschedule = false // start executing the batch immediately after the currently running task suspends // this is safe b/c `needsReschedule` is set to `true` only upon yielding to the event loop - queueMicrotask(() => executeBatchTask.run()) + queueMicrotask(executeBatchTaskJSFunction) () } }