Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
Potentially mitigate crashes in GameManager
Browse files Browse the repository at this point in the history
  • Loading branch information
inickt committed Nov 10, 2021
1 parent 3621573 commit 852c0e7
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions LazyManCore/Managers/GameManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)]
}
}
}

Expand All @@ -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
}
}
}

Expand Down

0 comments on commit 852c0e7

Please sign in to comment.