From 72adfe429d0c7275c699c65ef323f9bf10873ab7 Mon Sep 17 00:00:00 2001 From: wuyueyang Date: Sat, 19 Mar 2022 01:41:49 +0800 Subject: [PATCH] Fix a work may start multiple times --- MixinServices/MixinServices/Services/Work/WorkManager.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/MixinServices/MixinServices/Services/Work/WorkManager.swift b/MixinServices/MixinServices/Services/Work/WorkManager.swift index df70a4e662..ea1136fd21 100644 --- a/MixinServices/MixinServices/Services/Work/WorkManager.swift +++ b/MixinServices/MixinServices/Services/Work/WorkManager.swift @@ -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)