Skip to content

Commit

Permalink
Merge pull request #201 from fantast1k/fix-TUSClient-data-race-crash
Browse files Browse the repository at this point in the history
Fix TUSClient data racing issue
  • Loading branch information
donnywals authored Mar 3, 2025
2 parents 7363d0b + cfecd86 commit b8682f0
Show file tree
Hide file tree
Showing 13 changed files with 340 additions and 424 deletions.
23 changes: 20 additions & 3 deletions Sources/TUSKit/Scheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ final class Scheduler {
}
}

func cancelTask(by id: UUID) {
queue.async {
self.pendingTasks.removeAll { task in
guard let idTask = task as? IdentifiableTask, idTask.id == id else {
return false
}
idTask.cancel()
return true
}
self.runningTasks.removeAll { task in
guard let idTask = task as? IdentifiableTask, idTask.id == id else {
return false
}
idTask.cancel()
return true
}
}
}

func cancelTasks(_ tasksToCancel: [ScheduledTask]) {
queue.async {
tasksToCancel.forEach { taskToCancel in
Expand All @@ -76,7 +95,7 @@ final class Scheduler {
pendingTask.cancel()
self.pendingTasks.remove(at: pendingTaskIndex)
}

if let runningTaskIndex = self.runningTasks.firstIndex(where: { runningTask in
runningTask === taskToCancel
}) {
Expand Down Expand Up @@ -122,9 +141,7 @@ final class Scheduler {
}
self.checkProcessNextTask()
}

}

}
}

Expand Down
120 changes: 0 additions & 120 deletions Sources/TUSKit/TUSBackground.swift

This file was deleted.

Loading

0 comments on commit b8682f0

Please sign in to comment.