@@ -42,16 +42,33 @@ func readSource(from fileHandle: FileHandle) -> String? {
42
42
func processSources(
43
43
from paths: [ String ] , configurationPath: String ? ,
44
44
diagnosticEngine: DiagnosticEngine ,
45
- transform: ( FileHandle , String , Configuration ) -> Void
45
+ transform: @escaping ( FileHandle , String , Configuration ) -> Void
46
46
) throws {
47
+ let concurrentQueue = DispatchQueue ( label: " com.queue.Concurrent " , qos: . userInitiated, attributes: . concurrent)
48
+ let group = DispatchGroup ( )
49
+ let lock = NSLock ( )
50
+ var lastError : Error ?
47
51
for path in FileIterator ( paths: paths) {
48
- guard let sourceFile = FileHandle ( forReadingAtPath: path) else {
49
- diagnosticEngine. diagnose (
50
- Diagnostic . Message ( . error, " Unable to create a file handle for source from \( path) . " ) )
51
- return
52
+ concurrentQueue. async ( group: group) {
53
+ guard let sourceFile = FileHandle ( forReadingAtPath: path) else {
54
+ diagnosticEngine. diagnose (
55
+ Diagnostic . Message ( . error, " Unable to create a file handle for source from \( path) . " ) )
56
+ return
57
+ }
58
+ do {
59
+ let configuration = try loadConfiguration ( forSwiftFile: path, configFilePath: configurationPath)
60
+ transform ( sourceFile, path, configuration)
61
+ } catch let error {
62
+ lock. lock ( )
63
+ lastError = error
64
+ lock. unlock ( )
65
+ }
52
66
}
53
- let configuration = try loadConfiguration ( forSwiftFile: path, configFilePath: configurationPath)
54
- transform ( sourceFile, path, configuration)
67
+ }
68
+
69
+ group. wait ( )
70
+ if let error = lastError {
71
+ throw error
55
72
}
56
73
}
57
74
0 commit comments