From 852c0e7bc6e79feec6d47a4bb25afafa422a41b0 Mon Sep 17 00:00:00 2001 From: Nick Thompson Date: Tue, 9 Nov 2021 21:55:56 -0500 Subject: [PATCH] Potentially mitigate crashes in GameManager --- LazyManCore/Managers/GameManager.swift | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/LazyManCore/Managers/GameManager.swift b/LazyManCore/Managers/GameManager.swift index d36710c..b402352 100644 --- a/LazyManCore/Managers/GameManager.swift +++ b/LazyManCore/Managers/GameManager.swift @@ -57,6 +57,7 @@ public class GameManager: GameManagerType { private var nhlGames = [String : [Game]]() private var mlbGames = [String : [Game]]() private let scheduleLoader: ScheduleLoader + private let queue = DispatchQueue(label: "dev.nickt.LazyManCore.GameManager") // MARK: - Initialization @@ -127,11 +128,13 @@ public class GameManager: GameManagerType { } private func getGames(date: Date, league: League) -> [Game]? { - switch league { - case .NHL: - return self.nhlGames[DateUtils.convertToYYYYMMDD(from: date)] - case .MLB: - return self.mlbGames[DateUtils.convertToYYYYMMDD(from: date)] + return queue.sync { + switch league { + case .NHL: + return self.nhlGames[DateUtils.convertToYYYYMMDD(from: date)] + case .MLB: + return self.mlbGames[DateUtils.convertToYYYYMMDD(from: date)] + } } } @@ -140,11 +143,13 @@ public class GameManager: GameManagerType { } private func setGames(date: String, league: League, games: [Game]?) { - switch league { - case .NHL: - self.nhlGames[date] = games - case .MLB: - self.mlbGames[date] = games + queue.sync { + switch league { + case .NHL: + self.nhlGames[date] = games + case .MLB: + self.mlbGames[date] = games + } } }