This repository was archived by the owner on May 8, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed
Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -293,6 +293,7 @@ extension Fuse {
293293 let pattern = self . createPattern ( from: text)
294294
295295 var items = [ SearchResult] ( )
296+ let itemsLock = NSLock ( )
296297
297298 let group = DispatchGroup ( )
298299 let count = aList. count
@@ -303,7 +304,9 @@ extension Fuse {
303304 self . searchQueue. async {
304305 for (index, item) in chunk. enumerated ( ) {
305306 if let result = self . search ( pattern, in: item) {
307+ itemsLock. lock ( )
306308 items. append ( ( index, result. score, result. ranges) )
309+ itemsLock. unlock ( )
307310 }
308311 }
309312
@@ -447,6 +450,7 @@ extension Fuse {
447450 let count = aList. count
448451
449452 var collectionResult = [ FusableSearchResult] ( )
453+ let resultLock = NSLock ( )
450454
451455 stride ( from: 0 , to: count, by: chunkSize) . forEach {
452456 let chunk = Array ( aList [ $0..< min ( $0 + chunkSize, count) ] )
@@ -486,11 +490,13 @@ extension Fuse {
486490 continue
487491 }
488492
493+ resultLock. lock ( )
489494 collectionResult. append ( (
490495 index: index,
491496 score: totalScore / Double( scores. count) ,
492497 results: propertyResults
493498 ) )
499+ resultLock. unlock ( )
494500 }
495501
496502 group. leave ( )
You can’t perform that action at this time.
0 commit comments