Skip to content

Commit

Permalink
Fix ConcurrentModificationException when removing jobs (#195)
Browse files Browse the repository at this point in the history
Co-authored-by: Vasiliy Kulakov <[email protected]>
  • Loading branch information
ReallyVasiliy and Vasiliy Kulakov authored Jun 6, 2022
1 parent b91d1ce commit 1228e2d
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ class VideoFrameExtractor @JvmOverloads constructor(
* Cancels all started extract jobs. [FrameExtractListener.onCancelled] will be called for jobs that have been started.
*/
fun stopAll() {
activeJobMap.forEach { (requestId, job) ->
val iterator = activeJobMap.iterator()
while (iterator.hasNext()) {
val job = iterator.next().value
if (!job.future.isCancelled && !job.future.isDone) {
job.future.cancel(true)
}
if (!job.future.isStarted) {
// If the job hasn't started, it won't probably even start, but it will remain in the activeJobMap,
// we must remove it from there.
activeJobMap.remove(requestId)
iterator.remove()
}
}
}
Expand Down

0 comments on commit 1228e2d

Please sign in to comment.