Skip to content

Commit

Permalink
Introduce UncheckedSendable for Sendable closures
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Griselli <[email protected]>
  • Loading branch information
marcosgriselli committed Feb 27, 2024
1 parent 998aefe commit 0110877
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Source/SourceKittenFramework/SourceKitObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ public final class SourceKitObject {
}

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

return try await withTaskCancellationHandler {
try await withUnsafeThrowingContinuation { continuation in
sourcekitd_send_request(sourcekitdObject, handle) { response in
sourcekitd_send_request(sourcekitdObject, handle.value) { response in
enum SourceKitSendError: Error { case error, noResponse }

guard let response else {
Expand All @@ -130,7 +130,7 @@ public final class SourceKitObject {
}
}
} onCancel: {
sourcekitd_cancel_request(handle)
sourcekitd_cancel_request(handle.value)
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions Source/SourceKittenFramework/UncheckedSendable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct UncheckedSendable<Value>: @unchecked Sendable {
/// The unchecked value.
var value: Value

/// Initializes unchecked sendability around a value.
///
/// - Parameter value: A value to make sendable in an unchecked way.
init(_ value: Value) {
self.value = value
}
}

0 comments on commit 0110877

Please sign in to comment.