13
13
import Dispatch
14
14
import IndexStoreDB
15
15
import SKCore
16
+ import SKSupport
16
17
17
18
/// `IndexDelegate` for the SourceKit workspace.
18
19
///
19
20
/// *Public for testing*.
20
- public final class SourceKitIndexDelegate : IndexDelegate {
21
+ public actor SourceKitIndexDelegate : IndexDelegate {
21
22
22
- /// Provides mutual exclusion for other members.
23
- let queue : DispatchQueue = DispatchQueue ( label: " \( SourceKitIndexDelegate . self) -queue " )
23
+ let queue = AsyncQueue < Serial > ( )
24
24
25
25
/// Registered `MainFilesDelegate`s to notify when main files change.
26
26
var mainFilesDelegates : [ MainFilesDelegate ] = [ ]
@@ -32,47 +32,50 @@ public final class SourceKitIndexDelegate: IndexDelegate {
32
32
33
33
public init ( ) { }
34
34
35
- public func processingAddedPending( _ count: Int ) {
36
- queue. sync {
37
- pendingUnitCount += count
35
+ nonisolated public func processingAddedPending( _ count: Int ) {
36
+ queue. async {
37
+ await self . addPending ( count)
38
38
}
39
39
}
40
40
41
- public func processingCompleted( _ count: Int ) {
42
- queue. sync {
43
- pendingUnitCount -= count
44
- if pendingUnitCount == 0 {
45
- _indexChanged ( )
46
- }
41
+ private func addPending( _ count: Int ) {
42
+ pendingUnitCount += count
43
+ }
47
44
48
- if pendingUnitCount < 0 {
49
- assertionFailure ( " pendingUnitCount = \( pendingUnitCount) < 0 " )
50
- pendingUnitCount = 0
51
- _indexChanged ( )
52
- }
45
+ nonisolated public func processingCompleted( _ count: Int ) {
46
+ queue. async {
47
+ await self . processCompleted ( count)
48
+ }
49
+ }
50
+
51
+ private func processCompleted( _ count: Int ) {
52
+ pendingUnitCount -= count
53
+ if pendingUnitCount == 0 {
54
+ _indexChanged ( )
55
+ }
56
+
57
+ if pendingUnitCount < 0 {
58
+ assertionFailure ( " pendingUnitCount = \( pendingUnitCount) < 0 " )
59
+ pendingUnitCount = 0
60
+ _indexChanged ( )
53
61
}
54
62
}
55
63
56
- /// *Must be called on queue*.
57
64
func _indexChanged( ) {
58
65
for delegate in mainFilesDelegates {
59
- Task {
66
+ queue . async {
60
67
await delegate. mainFilesChanged ( )
61
68
}
62
69
}
63
70
}
64
71
65
72
/// Register a delegate to receive notifications when main files change.
66
73
public func registerMainFileChanged( _ delegate: MainFilesDelegate ) {
67
- queue. sync {
68
- mainFilesDelegates. append ( delegate)
69
- }
74
+ mainFilesDelegates. append ( delegate)
70
75
}
71
76
72
77
/// Un-register a delegate to receive notifications when main files change.
73
78
public func unregisterMainFileChanged( _ delegate: MainFilesDelegate ) {
74
- queue. sync {
75
- mainFilesDelegates. removeAll ( where: { $0 === delegate } )
76
- }
79
+ mainFilesDelegates. removeAll ( where: { $0 === delegate } )
77
80
}
78
81
}
0 commit comments