GeezerVison is showing github.com — Merge pull request #443 from swiftwasm/yt/schedulable-executor-rename · wfltaylor/JavaScriptKit@0b78561
File treeExpand file treeCollapse file tree Open diff view settings Plugins/PackageToJS/Tests Sources/JavaScriptEventLoop
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test.yml +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,12 +21,12 @@ jobs: | 21 | 21 | target: "wasm32-unknown-wasi" | 22 | 22 | - os: ubuntu-22.04 | 23 | 23 | toolchain: | 24 | | - download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a-ubuntu22.04.tar.gz | | 24 | + download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-08-27-a/swift-DEVELOPMENT-SNAPSHOT-2025-08-27-a-ubuntu22.04.tar.gz | 25 | 25 | wasi-backend: Node | 26 | | - target: "wasm32-unknown-wasi" | | 26 | + target: "wasm32-unknown-wasip1" | 27 | 27 | - os: ubuntu-22.04 | 28 | 28 | toolchain: | 29 | | - download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a-ubuntu22.04.tar.gz | | 29 | + download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-08-27-a/swift-DEVELOPMENT-SNAPSHOT-2025-08-27-a-ubuntu22.04.tar.gz | 30 | 30 | wasi-backend: Node | 31 | 31 | target: "wasm32-unknown-wasip1-threads" | 32 | 32 |
| | 95 | 95 | - uses: actions/checkout@v5 | 96 | 96 | - uses: ./.github/actions/install-swift | 97 | 97 | with: | 98 | | - download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a-ubuntu22.04.tar.gz | | 98 | + download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-08-27-a/swift-DEVELOPMENT-SNAPSHOT-2025-08-27-a-ubuntu22.04.tar.gz | 99 | 99 | - run: make bootstrap | 100 | 100 | - run: ./Utilities/bridge-js-generate.sh | 101 | 101 | - name: Check if BridgeJS generated files are up-to-date | @@ -112,17 +112,17 @@ jobs: | 112 | 112 | - uses: actions/checkout@v5 | 113 | 113 | - uses: ./.github/actions/install-swift | 114 | 114 | with: | 115 | | - download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a-ubuntu22.04.tar.gz | | 115 | + download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-08-27-a/swift-DEVELOPMENT-SNAPSHOT-2025-08-27-a-ubuntu22.04.tar.gz | 116 | 116 | - uses: swiftwasm/setup-swiftwasm@v2 | 117 | | - id: setup-wasm32-unknown-wasi | 118 | | - with: { target: wasm32-unknown-wasi } | | 117 | + id: setup-wasm32-unknown-wasip1 | | 118 | + with: { target: wasm32-unknown-wasip1 } | 119 | 119 | - uses: swiftwasm/setup-swiftwasm@v2 | 120 | 120 | id: setup-wasm32-unknown-wasip1-threads | 121 | 121 | with: { target: wasm32-unknown-wasip1-threads } | 122 | 122 | - run: ./Utilities/build-examples.sh | 123 | 123 | env: | 124 | 124 | SWIFT_SDK_ID_wasm32_unknown_wasip1_threads: ${{ steps.setup-wasm32-unknown-wasip1-threads.outputs.swift-sdk-id }} | 125 | | - SWIFT_SDK_ID_wasm32_unknown_wasi: ${{ steps.setup-wasm32-unknown-wasi.outputs.swift-sdk-id }} | | 125 | + SWIFT_SDK_ID_wasm32_unknown_wasip1: ${{ steps.setup-wasm32-unknown-wasip1.outputs.swift-sdk-id }} | 126 | 126 | - name: Upload static files as artifact | 127 | 127 | id: deployment | 128 | 128 | uses: actions/upload-pages-artifact@v4 | |
Collapse file Copy file name to clipboard +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #!/bin/bash | 2 | 2 | set -euxo pipefail | 3 | | -swift package --swift-sdk "${SWIFT_SDK_ID_wasm32_unknown_wasi:-${SWIFT_SDK_ID:-wasm32-unknown-wasi}}" -c "${1:-debug}" js --use-cdn | | 3 | +swift package --swift-sdk "${SWIFT_SDK_ID_wasm32_unknown_wasip1:-${SWIFT_SDK_ID:-wasm32-unknown-wasip1}}" -c "${1:-debug}" js --use-cdn |
Collapse file Copy file name to clipboard +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | #!/bin/bash | 2 | 2 | set -euxo pipefail | 3 | | -env JAVASCRIPTKIT_EXPERIMENTAL_BRIDGEJS=1 swift package --swift-sdk "${SWIFT_SDK_ID_wasm32_unknown_wasi:-${SWIFT_SDK_ID:-wasm32-unknown-wasi}}" -c "${1:-debug}" \ | | 3 | +env JAVASCRIPTKIT_EXPERIMENTAL_BRIDGEJS=1 swift package --swift-sdk "${SWIFT_SDK_ID_wasm32_unknown_wasip1:-${SWIFT_SDK_ID:-wasm32-unknown-wasip1}}" -c "${1:-debug}" \ | 4 | 4 | plugin --allow-writing-to-package-directory \ | 5 | 5 | js --use-cdn --output ./Bundle |
Collapse file Copy file name to clipboardExpand all lines: Plugins/PackageToJS/Tests/ExampleTests.swift +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -80,6 +80,14 @@ extension Trait where Self == ConditionTrait { | 80 | 80 | else { | 81 | 81 | return false | 82 | 82 | } | | 83 | + guard | | 84 | + ["wasm32-unknown-wasi", "wasm32-unknown-wasip1"].contains(where: { | | 85 | + swiftSDKID.hasSuffix($0) | | 86 | + }) | | 87 | + else { | | 88 | + // Only non-threads SDKs are supported for embedded in Swift SDK | | 89 | + return false | | 90 | + } | 83 | 91 | let embeddedSDKID = "\(swiftSDKID)-embedded" | 84 | 92 | return isSwiftSDKAvailable(embeddedSDKID, swiftPath: swiftPath) | 85 | 93 | }(), | @@ -206,6 +214,7 @@ extension Trait where Self == ConditionTrait { | 206 | 214 | Swift package should build successfully, check \(destination.appending(path: path).path) for details | 207 | 215 | stdout: \(stdoutPath.path) | 208 | 216 | stderr: \(stderrPath.path) | | 217 | + arguments: \(args) | 209 | 218 |
| 210 | 219 | \((try? String(contentsOf: stdoutPath, encoding: .utf8)) ?? "<<stdout is empty>>") | 211 | 220 | \((try? String(contentsOf: stderrPath, encoding: .utf8)) ?? "<<stderr is empty>>") | |
Collapse file Copy file name to clipboardExpand all lines: Sources/JavaScriptEventLoop/JavaScriptEventLoop+ExecutorFactory.swift +20-5Lines changed: 20 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,22 +27,37 @@ extension JavaScriptEventLoop: MainExecutor { | 27 | 27 | extension JavaScriptEventLoop: TaskExecutor {} | 28 | 28 |
| 29 | 29 | @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999, *) | 30 | | -extension JavaScriptEventLoop: SchedulableExecutor { | | 30 | +extension JavaScriptEventLoop: SchedulingExecutor { | 31 | 31 | public func enqueue<C: Clock>( | 32 | 32 | _ job: consuming ExecutorJob, | 33 | 33 | after delay: C.Duration, | 34 | 34 | tolerance: C.Duration?, | 35 | 35 | clock: C | 36 | 36 | ) { | 37 | | - let milliseconds = Self.delayInMilliseconds(from: delay, clock: clock) | | 37 | + let duration: Duration | | 38 | + // Handle clocks we know | | 39 | + if let _ = clock as? ContinuousClock { | | 40 | + duration = delay as! ContinuousClock.Duration | | 41 | + } else if let _ = clock as? SuspendingClock { | | 42 | + duration = delay as! SuspendingClock.Duration | | 43 | + } else { | | 44 | + // Hand-off the scheduling work to Clock implementation for unknown clocks | | 45 | + clock.enqueue( | | 46 | + job, | | 47 | + on: self, | | 48 | + at: clock.now.advanced(by: delay), | | 49 | + tolerance: tolerance | | 50 | + ) | | 51 | + return | | 52 | + } | | 53 | + let milliseconds = Self.delayInMilliseconds(from: duration) | 38 | 54 | self.enqueue( | 39 | 55 | UnownedJob(job), | 40 | 56 | withDelay: milliseconds | 41 | 57 | ) | 42 | 58 | } | 43 | 59 |
| 44 | | - private static func delayInMilliseconds<C: Clock>(from duration: C.Duration, clock: C) -> Double { | 45 | | - let swiftDuration = clock.convert(from: duration)! | | 60 | + private static func delayInMilliseconds(from swiftDuration: Duration) -> Double { | 46 | 61 | let (seconds, attoseconds) = swiftDuration.components | 47 | 62 | return Double(seconds) * 1_000 + (Double(attoseconds) / 1_000_000_000_000_000) | 48 | 63 | } | @@ -52,7 +67,7 @@ extension JavaScriptEventLoop: SchedulableExecutor { | 52 | 67 | @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999, *) | 53 | 68 | extension JavaScriptEventLoop: ExecutorFactory { | 54 | 69 | // Forward all operations to the current thread's JavaScriptEventLoop instance | 55 | | - final class CurrentThread: TaskExecutor, SchedulableExecutor, MainExecutor, SerialExecutor { | | 70 | + final class CurrentThread: TaskExecutor, SchedulingExecutor, MainExecutor, SerialExecutor { | 56 | 71 | func checkIsolated() {} | 57 | 72 |
| 58 | 73 | func enqueue(_ job: consuming ExecutorJob) { | |
|