Skip to content

Commit 01ad530

Browse files
Introduce UncheckedSendable for Sendable closures (#806)
Signed-off-by: Marcos Griselli <[email protected]>
1 parent 998aefe commit 01ad530

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Source/SourceKittenFramework/SourceKitObject.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ public final class SourceKitObject {
110110
}
111111

112112
func sendAsync() async throws -> sourcekitd_response_t {
113-
let handle = UnsafeMutablePointer<sourcekitd_request_handle_t?>.allocate(capacity: 1)
113+
let handle = UncheckedSendable(UnsafeMutablePointer<sourcekitd_request_handle_t?>.allocate(capacity: 1))
114114

115115
return try await withTaskCancellationHandler {
116116
try await withUnsafeThrowingContinuation { continuation in
117-
sourcekitd_send_request(sourcekitdObject, handle) { response in
117+
sourcekitd_send_request(sourcekitdObject, handle.value) { response in
118118
enum SourceKitSendError: Error { case error, noResponse }
119119

120120
guard let response else {
@@ -130,7 +130,7 @@ public final class SourceKitObject {
130130
}
131131
}
132132
} onCancel: {
133-
sourcekitd_cancel_request(handle)
133+
sourcekitd_cancel_request(handle.value)
134134
}
135135
}
136136
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct UncheckedSendable<Value>: @unchecked Sendable {
2+
/// The unchecked value.
3+
var value: Value
4+
5+
/// Initializes unchecked sendability around a value.
6+
///
7+
/// - Parameter value: A value to make sendable in an unchecked way.
8+
init(_ value: Value) {
9+
self.value = value
10+
}
11+
}

0 commit comments

Comments
 (0)