diff --git a/EssentialApp/EssentialApp/SceneDelegate.swift b/EssentialApp/EssentialApp/SceneDelegate.swift index 063967d0..32cefcbe 100644 --- a/EssentialApp/EssentialApp/SceneDelegate.swift +++ b/EssentialApp/EssentialApp/SceneDelegate.swift @@ -68,10 +68,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } func sceneWillResignActive(_ scene: UIScene) { - do { - try localFeedLoader.validateCache() - } catch { - logger.error("Failed to validate cache with error: \(error.localizedDescription)") + scheduler.schedule { [localFeedLoader, logger] in + do { + try localFeedLoader.validateCache() + } catch { + logger.error("Failed to validate cache with error: \(error.localizedDescription)") + } } } @@ -92,10 +94,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { private func makeRemoteFeedLoaderWithLocalFallback() -> AnyPublisher, Error> { makeRemoteFeedLoader() + .receive(on: scheduler) .caching(to: localFeedLoader) .fallback(to: localFeedLoader.loadPublisher) .map(makeFirstPage) - .subscribe(on: scheduler) .eraseToAnyPublisher() } @@ -106,6 +108,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { (cachedItems + newItems, newItems.last) } .map(makePage) + .receive(on: scheduler) .caching(to: localFeedLoader) .subscribe(on: scheduler) .eraseToAnyPublisher() @@ -139,8 +142,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { httpClient .getPublisher(url: url) .tryMap(FeedImageDataMapper.map) + .receive(on: scheduler) .caching(to: localImageLoader, using: url) - .subscribe(on: scheduler) .eraseToAnyPublisher() }) .subscribe(on: scheduler)