Skip to content

Commit d3b26d3

Browse files
Merge pull request #344 from swiftwasm/maxd/embedded-concurrency1
Fix some Embedded Swift issues in `JavaScriptEventLoop`
2 parents cacbd52 + 86e2095 commit d3b26d3

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

Sources/JavaScriptEventLoop/JSSending.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import _Concurrency
12
@_spi(JSObject_id) import JavaScriptKit
23
import _CJavaScriptKit
34

Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import JavaScriptKit
2+
import _Concurrency
23
import _CJavaScriptEventLoop
34
import _CJavaScriptKit
45

@@ -259,38 +260,38 @@ extension JavaScriptEventLoop {
259260
extension JSPromise {
260261
/// Wait for the promise to complete, returning (or throwing) its result.
261262
public var value: JSValue {
262-
get async throws {
263-
try await withUnsafeThrowingContinuation { [self] continuation in
263+
get async throws(JSException) {
264+
try await withUnsafeContinuation { [self] continuation in
264265
self.then(
265266
success: {
266-
continuation.resume(returning: $0)
267+
continuation.resume(returning: Swift.Result<JSValue, JSException>.success($0))
267268
return JSValue.undefined
268269
},
269270
failure: {
270-
continuation.resume(throwing: JSException($0))
271+
continuation.resume(returning: Swift.Result<JSValue, JSException>.failure(.init($0)))
271272
return JSValue.undefined
272273
}
273274
)
274-
}
275+
}.get()
275276
}
276277
}
277278

278279
/// Wait for the promise to complete, returning its result or exception as a Result.
279280
///
280281
/// - Note: Calling this function does not switch from the caller's isolation domain.
281-
public func value(isolation: isolated (any Actor)? = #isolation) async throws -> JSValue {
282-
try await withUnsafeThrowingContinuation(isolation: isolation) { [self] continuation in
282+
public func value(isolation: isolated (any Actor)? = #isolation) async throws(JSException) -> JSValue {
283+
try await withUnsafeContinuation(isolation: isolation) { [self] continuation in
283284
self.then(
284285
success: {
285-
continuation.resume(returning: $0)
286+
continuation.resume(returning: Swift.Result<JSValue, JSException>.success($0))
286287
return JSValue.undefined
287288
},
288289
failure: {
289-
continuation.resume(throwing: JSException($0))
290+
continuation.resume(returning: Swift.Result<JSValue, JSException>.failure(.init($0)))
290291
return JSValue.undefined
291292
}
292293
)
293-
}
294+
}.get()
294295
}
295296

296297
/// Wait for the promise to complete, returning its result or exception as a Result.

Sources/JavaScriptEventLoop/JobQueue.swift

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The current implementation is much simple to be easily debugged, but should be re-implemented
33
// using priority queue ideally.
44

5+
import _Concurrency
56
import _CJavaScriptEventLoop
67

78
#if compiler(>=5.5)

Sources/JavaScriptEventLoop/WebWorkerDedicatedExecutor.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#if !hasFeature(Embedded)
12
import JavaScriptKit
23
import _CJavaScriptEventLoop
4+
import _Concurrency
35

46
#if canImport(Synchronization)
57
import Synchronization
@@ -60,3 +62,4 @@ public final class WebWorkerDedicatedExecutor: SerialExecutor {
6062
self.underlying.enqueue(job)
6163
}
6264
}
65+
#endif

Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if compiler(>=6.0) // `TaskExecutor` is available since Swift 6.0
1+
#if compiler(>=6.0) && !hasFeature(Embedded) // `TaskExecutor` is available since Swift 6.0, no multi-threading for embedded Wasm yet.
22

33
import JavaScriptKit
44
import _CJavaScriptKit

0 commit comments

Comments
 (0)