Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion podcasts/New Detail/PlaylistDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ class PlaylistDetailViewModel: ObservableObject {
private let onChange: (StagedChangeset<DataSourceValue>, Bool, Bool) -> Void
private var tempEpisodes: [ListEpisode] = []

private var updateTask: Task<Void, Never>?

private lazy var operationQueue: OperationQueue = {
let queue = OperationQueue()
queue.maxConcurrentOperationCount = 1
return queue
}()

deinit {
updateTask?.cancel()
}

init(
playlist: EpisodeFilter,
dataManager: DataManager = .sharedManager,
Expand All @@ -79,7 +85,9 @@ class PlaylistDetailViewModel: ObservableObject {
if isLoadingData { return }
isLoadingData = true

Task { [weak self] in
updateTask?.cancel()

updateTask = Task { [weak self] in
guard let self else { return }
do {
let count = await self.getEpisodesCount()
Expand Down
12 changes: 10 additions & 2 deletions podcasts/PlaylistCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ class PlaylistCellViewModel: ObservableObject {
private let episodesDataManager: EpisodesDataManager
private let episodeArtWork: EpisodeArtwork

private var countTask: Task<Void, Never>?
private var imagesTask: Task<Void, Never>?

let displayType: DisplayType

deinit {
countTask?.cancel()
imagesTask?.cancel()
}

init(
playlist: EpisodeFilter,
displayType: DisplayType = .count,
Expand Down Expand Up @@ -71,7 +79,7 @@ class PlaylistCellViewModel: ObservableObject {
private func loadCount() {
if isLoadingCount { return }
isLoadingCount = true
Task { [weak self] in
countTask = Task { [weak self] in
guard let self else { return }
let count = await self.getEpisodesCount()
await MainActor.run {
Expand All @@ -84,7 +92,7 @@ class PlaylistCellViewModel: ObservableObject {
private func loadImages() {
if isLoadingImages { return }
isLoadingImages = true
Task { [weak self] in
imagesTask = Task { [weak self] in
guard let self else { return }
do {
let list = await self.loadListEpisodes()
Expand Down