Skip to content

Commit d0f49ad

Browse files
committedOct 3, 2022
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) }) } ```
1 parent a549f58 commit d0f49ad

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed
 

Diff for: ‎Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
3939

4040
/// A function that queues a given closure as a microtask into JavaScript event loop.
4141
/// See also: https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide
42-
let queueMicrotask: @Sendable (@escaping () -> Void) -> Void
42+
public var queueMicrotask: @Sendable (@escaping () -> Void) -> Void
4343
/// A function that invokes a given closure after a specified number of milliseconds.
44-
let setTimeout: @Sendable (Double, @escaping () -> Void) -> Void
44+
public var setTimeout: @Sendable (Double, @escaping () -> Void) -> Void
4545

4646
/// A mutable state to manage internal job queue
4747
/// Note that this should be guarded atomically when supporting multi-threaded environment.

0 commit comments

Comments
 (0)