JavaScriptKit Documentation

Class Java​Script​Event​Loop

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable  

Singleton type responsible for integrating JavaScript event loop as a Swift concurrency executor, conforming to SerialExecutor protocol from the standard library. To utilize it:

  1. Make sure that your target depends on JavaScriptEventLoop in your Packages.swift:
    name: "JavaScriptKitExample",
    dependencies: [
        .product(name: "JavaScriptEventLoop", package: "JavaScriptKit")
  1. Add an explicit import in the code that executes *before you start using await and/or Task APIs (most likely in main.swift):
import JavaScriptEventLoop
  1. Run this function *before you start using await and/or Task APIs (again, most likely in main.swift):
%69 JavaScriptEventLoop JavaScriptEventLoop @unchecked Sendable @unchecked Sendable JavaScriptEventLoop->@unchecked Sendable SerialExecutor SerialExecutor JavaScriptEventLoop->SerialExecutor

Conforms To

@unchecked Sendable



public var queueMicrotask: @Sendable (@escaping () -> Void) -> Void

A function that queues a given closure as a microtask into JavaScript event loop. See also:


public var setTimeout: @Sendable (Double, @escaping () -> Void) -> Void

A function that invokes a given closure after a specified number of milliseconds.


public static let shared: JavaScriptEventLoop  

A singleton instance of the Executor



public static func installGlobalExecutor()  

Set JavaScript event loop based executor to be the global executor Note that this should be called before any of the jobs are created. This installation step will be unnecessary after custom executor are introduced officially. See also a draft proposal for custom executors


public func enqueue(_ job: UnownedJob)  


public func asUnownedSerialExecutor() -> UnownedSerialExecutor