File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Sources/JavaScriptKit/FundamentalObjects Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,27 @@ public class JSClosure: JSObject, JSClosureProtocol {
84
84
Self . sharedClosures [ hostFuncRef] = ( self , body)
85
85
}
86
86
87
+ #if compiler(>=5.5)
88
+ static func async ( _ body: @escaping ( [ JSValue ] ) async throws -> JSValue ) -> JSClosure {
89
+ JSClosure { arguments in
90
+ JSPromise { resolver in
91
+ Task {
92
+ do {
93
+ let result = try await body ( arguments)
94
+ resolver ( . success( result) )
95
+ } catch {
96
+ if let jsError = error as? JSError {
97
+ resolver ( . failure( jsError. jsValue ( ) ) )
98
+ } else {
99
+ resolver ( . failure( JSError ( message: String ( describing: error) ) . jsValue ( ) ) )
100
+ }
101
+ }
102
+ }
103
+ } . jsValue ( )
104
+ }
105
+ }
106
+ #endif
107
+
87
108
#if JAVASCRIPTKIT_WITHOUT_WEAKREFS
88
109
deinit {
89
110
guard isReleased else {
You can’t perform that action at this time.
0 commit comments