From d0f49adff30ba0bfef2117a33dc6501341264a41 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 3 Oct 2022 12:06:07 +0000 Subject: [PATCH] Expose JavaScriptEventLoop.queueMicrotask and .setTimeout This allows users to have more flexibility to customize. For example, this allows inserting operations before/after single job execution loop. e.g. It's useful to enable React batch rendering per job execution loop by `ReactDOM.unstable_batchedUpdates`. ```swift let original = JavaScriptEventLoop.shared.queueMicrotask JavaScriptEventLoop.shared.queueMicrotask = (job) => { ReactDOM.unstable_batchedUpdates(() => { original(job) }) } ``` --- Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift b/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift index d8f4ad0ad..7c4a1c905 100644 --- a/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift +++ b/Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift @@ -39,9 +39,9 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable { /// A function that queues a given closure as a microtask into JavaScript event loop. /// See also: https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide - let queueMicrotask: @Sendable (@escaping () -> Void) -> Void + public var queueMicrotask: @Sendable (@escaping () -> Void) -> Void /// A function that invokes a given closure after a specified number of milliseconds. - let setTimeout: @Sendable (Double, @escaping () -> Void) -> Void + public var setTimeout: @Sendable (Double, @escaping () -> Void) -> Void /// A mutable state to manage internal job queue /// Note that this should be guarded atomically when supporting multi-threaded environment.