Skip to content

Commit b8682f0

Browse files
authored
Merge pull request #201 from fantast1k/fix-TUSClient-data-race-crash
Fix TUSClient data racing issue
2 parents 7363d0b + cfecd86 commit b8682f0

13 files changed

+340
-424
lines changed

Sources/TUSKit/Scheduler.swift

+20-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ final class Scheduler {
6666
}
6767
}
6868

69+
func cancelTask(by id: UUID) {
70+
queue.async {
71+
self.pendingTasks.removeAll { task in
72+
guard let idTask = task as? IdentifiableTask, idTask.id == id else {
73+
return false
74+
}
75+
idTask.cancel()
76+
return true
77+
}
78+
self.runningTasks.removeAll { task in
79+
guard let idTask = task as? IdentifiableTask, idTask.id == id else {
80+
return false
81+
}
82+
idTask.cancel()
83+
return true
84+
}
85+
}
86+
}
87+
6988
func cancelTasks(_ tasksToCancel: [ScheduledTask]) {
7089
queue.async {
7190
tasksToCancel.forEach { taskToCancel in
@@ -76,7 +95,7 @@ final class Scheduler {
7695
pendingTask.cancel()
7796
self.pendingTasks.remove(at: pendingTaskIndex)
7897
}
79-
98+
8099
if let runningTaskIndex = self.runningTasks.firstIndex(where: { runningTask in
81100
runningTask === taskToCancel
82101
}) {
@@ -122,9 +141,7 @@ final class Scheduler {
122141
}
123142
self.checkProcessNextTask()
124143
}
125-
126144
}
127-
128145
}
129146
}
130147

Sources/TUSKit/TUSBackground.swift

-120
This file was deleted.

0 commit comments

Comments
 (0)