Skip to content

Commit

Permalink
Fix a work may start multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyuehyang committed Apr 11, 2022
1 parent 43bf693 commit ee9f873
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions MixinServices/MixinServices/Services/Work/WorkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ extension WorkManager: WorkStateMonitor {
assertionFailure("No way a work becomes preparing")
case .ready:
lock.lock()
if executingWorks.count < maxConcurrentWorkCount {
if executingWorks.count < maxConcurrentWorkCount, let pendingWorksIndex = pendingWorks.firstIndex(of: work) {
Logger.general.debug(category: "WorkManager", message: "[\(label)] Execute \(work) because of readiness change")
if let index = pendingWorks.firstIndex(of: work) {
pendingWorks.remove(at: index)
}
pendingWorks.remove(at: pendingWorksIndex)
executingWorks.insert(work)
lock.unlock()
dispatchQueue.async(execute: work.start)
Expand Down

0 comments on commit ee9f873

Please sign in to comment.