Skip to content

Commit

Permalink
Merge pull request onevcat#866 from onevcat/fix/stack-fetcher-cache
Browse files Browse the repository at this point in the history
Avoid stackoverflow in image prefetcher cache
  • Loading branch information
onevcat authored Feb 27, 2018
2 parents 9208ffe + 333400b commit 956b3f0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Sources/ImagePrefetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ public class ImagePrefetcher {
self.handleComplete()
}
} else {
DispatchQueue.main.async {
self.reportCompletionOrStartNext()
}
self.reportCompletionOrStartNext()
}
}

Expand Down Expand Up @@ -250,11 +248,13 @@ public class ImagePrefetcher {
}

func reportCompletionOrStartNext() {
if let resource = pendingResources.popFirst() {
startPrefetching(resource)
} else {
guard tasks.isEmpty else { return }
handleComplete()
DispatchQueue.main.async {
if let resource = self.pendingResources.popFirst() {
self.startPrefetching(resource)
} else {
guard self.tasks.isEmpty else { return }
self.handleComplete()
}
}
}

Expand Down

0 comments on commit 956b3f0

Please sign in to comment.