Skip to content

Commit 1db28fd

Browse files
Detach async JS bridge tasks
1 parent 59fd702 commit 1db28fd

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

Sources/JavaScriptKit/BasicObjects/JSPromise.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public final class JSPromise: JSBridgedClass {
9696
let body: () async throws(JSException) -> JSValue
9797
}
9898
let context = Context(resolver: resolver, body: body)
99-
Task {
99+
// Detach the task so the JS bridge does not inherit an arbitrary caller executor.
100+
Task.detached {
100101
do throws(JSException) {
101102
let result = try await context.body()
102103
context.resolver(.success(result))

Sources/JavaScriptKit/FundamentalObjects/JSClosure.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private func makeAsyncClosure(
353353
let body: (sending [JSValue]) async throws(JSException) -> JSValue
354354
}
355355
let context = Context(resolver: resolver, arguments: arguments, body: body)
356-
Task(priority: priority) {
356+
Task.detached(priority: priority) {
357357
do throws(JSException) {
358358
let result = try await context.body(context.arguments)
359359
context.resolver(.success(result))

0 commit comments

Comments
 (0)