Skip to content

Commit

Permalink
Cache executeBatchTaskJSFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Jan 28, 2023
1 parent 51ca39e commit 12afda7
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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)
()
}
}
Expand Down

0 comments on commit 12afda7

Please sign in to comment.