@@ -79,6 +79,7 @@ public struct JSSending<T>: @unchecked Sendable {
79
79
}
80
80
}
81
81
82
+ @available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
82
83
extension JSSending where T == JSObject {
83
84
private init ( _ object: JSObject , transferring: Bool ) {
84
85
self . init (
@@ -165,6 +166,7 @@ extension JSSending where T == JSObject {
165
166
}
166
167
}
167
168
169
+ @available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
168
170
extension JSSending {
169
171
170
172
/// Receives a sent `JSObject` from a thread.
@@ -227,6 +229,8 @@ extension JSSending {
227
229
#endif
228
230
}
229
231
232
+ // 6.0 and below can't compile the following without a compiler crash.
233
+ #if compiler(>=6.1)
230
234
/// Receives multiple `JSSending` instances from a thread in a single operation.
231
235
///
232
236
/// This method is more efficient than receiving multiple objects individually, as it
@@ -257,10 +261,12 @@ extension JSSending {
257
261
/// - isolation: The actor isolation context for this call, used in Swift concurrency.
258
262
/// - Returns: A tuple containing the received objects.
259
263
/// - Throws: `JSSendingError` if any sending operation fails, or `JSException` if a JavaScript error occurs.
264
+ @available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
260
265
public static func receive< each U > (
261
266
_ sendings: repeat JSSending < each U > ,
262
267
isolation: isolated ( any Actor ) ? = #isolation, file: StaticString = #file, line: UInt = #line
263
268
) async throws -> ( repeat each U ) where T == ( repeat each U ) {
269
+ #if compiler(>=6.1) && _runtime(_multithreaded)
264
270
var sendingObjects : [ JavaScriptObjectRef ] = [ ]
265
271
var transferringObjects : [ JavaScriptObjectRef ] = [ ]
266
272
var sourceTid : Int32 ?
@@ -302,9 +308,14 @@ extension JSSending {
302
308
return sending. storage. construct ( result. object!)
303
309
}
304
310
return ( repeat extract( each sendings) )
311
+ #else
312
+ return try await ( repeat ( each sendings) . receive ( ) )
313
+ #endif
305
314
}
315
+ #endif // compiler(>=6.1)
306
316
}
307
317
318
+ @available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
308
319
fileprivate final class _JSSendingContext : Sendable {
309
320
let continuation : CheckedContinuation < JavaScriptObjectRef , Error >
310
321
0 commit comments