@@ -69,18 +69,36 @@ fileprivate func main(_ arguments: [String]) -> Int32 {
69
69
/// - transform: A closure that performs a transformation on a specific source file.
70
70
private func processSources(
71
71
from paths: [ String ] , configurationPath: String ? ,
72
- transform: ( FileHandle , String , Configuration ) -> Int
72
+ transform: @escaping ( FileHandle , String , Configuration ) -> Int
73
73
) -> Int32 {
74
74
var result = 0
75
+ let concurrentQueue = DispatchQueue ( label: " com.queue.Concurrent " , qos: . userInitiated, attributes: . concurrent)
76
+ let group = DispatchGroup ( )
77
+ let lock = NSLock ( )
75
78
for path in FileIterator ( paths: paths) {
76
- guard let sourceFile = FileHandle ( forReadingAtPath: path) else {
77
- stderrStream. write ( " Unable to create a file handle for source from \( path) . \n " )
78
- stderrStream. flush ( )
79
- return 1
79
+ group. enter ( )
80
+ concurrentQueue. async {
81
+ defer { group. leave ( ) }
82
+ guard let sourceFile = FileHandle ( forReadingAtPath: path) else {
83
+ stderrStream. write ( " Unable to create a file handle for source from \( path) . \n " )
84
+ stderrStream. flush ( )
85
+ lock. lock ( )
86
+ result |= 1
87
+ lock. unlock ( )
88
+ return
89
+ }
90
+
91
+ let configuration = loadConfiguration ( forSwiftFile: path, configFilePath: configurationPath)
92
+ let transformResult = transform ( sourceFile, path, configuration)
93
+ if transformResult > 0 {
94
+ lock. lock ( )
95
+ result |= transformResult
96
+ lock. unlock ( )
97
+ }
80
98
}
81
- let configuration = loadConfiguration ( forSwiftFile: path, configFilePath: configurationPath)
82
- result |= transform ( sourceFile, path, configuration)
83
99
}
100
+
101
+ group. wait ( )
84
102
return Int32 ( result)
85
103
}
86
104
0 commit comments