@@ -52,16 +52,16 @@ fileprivate struct NotificationTimeoutError: Error, CustomStringConvertible {
52
52
/// We can't use an `AsyncStream` for this because an `AsyncStream` is cancelled if a task that calls
53
53
/// `AsyncStream.Iterator.next` is cancelled and we want to be able to wait for new notifications even if waiting for a
54
54
/// a previous notification timed out.
55
- actor PendingNotifications {
56
- private var values : [ any NotificationType ] = [ ]
55
+ final class PendingNotifications : Sendable {
56
+ private let values = ThreadSafeBox < [ any NotificationType ] > ( initialValue : [ ] )
57
57
58
- func add( _ value: any NotificationType ) {
59
- values. insert ( value, at: 0 )
58
+ nonisolated func add( _ value: any NotificationType ) {
59
+ values. value . insert ( value, at: 0 )
60
60
}
61
61
62
62
func next( timeout: Duration , pollingInterval: Duration = . milliseconds( 10 ) ) async throws -> any NotificationType {
63
63
for _ in 0 ..< Int ( timeout. seconds / pollingInterval. seconds) {
64
- if let value = values. popLast ( ) {
64
+ if let value = values. value . popLast ( ) {
65
65
return value
66
66
}
67
67
try await Task . sleep ( for: pollingInterval)
@@ -358,9 +358,7 @@ package final class TestSourceKitLSPClient: MessageHandler, Sendable {
358
358
359
359
/// - Important: Implementation detail of `TestSourceKitLSPServer`. Do not call from tests.
360
360
package func handle( _ notification: some NotificationType ) {
361
- Task {
362
- await notifications. add ( notification)
363
- }
361
+ notifications. add ( notification)
364
362
}
365
363
366
364
/// - Important: Implementation detail of `TestSourceKitLSPClient`. Do not call from tests.
0 commit comments