Last active
April 9, 2024 06:46
-
-
Save SysCall97/bd1b64352de981a7bf0b9aca75429cb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class SplashViewController: UIViewController { | |
var launchDataDispatchGroup: DispatchGroup = DispatchGroup() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
DispatchQueue.global().async { [weak self] in | |
self?.getAppLaunchData() | |
} | |
} | |
private func getAppLaunchData() { | |
launchDataDispatchGroup.enter() | |
NetworkManager.shared.getData(for: .appConfig) { response in | |
launchDataDispatchGroup.leave() | |
// whatever you want to do with the response | |
} | |
launchDataDispatchGroup.enter() | |
NetworkManager.shared.getData(for: .user) { response in | |
launchDataDispatchGroup.leave() | |
// whatever you want to do with the response | |
} | |
launchDataDispatchGroup.enter() | |
NetworkManager.shared.getData(for: .longResponseTimeAPI) { response in | |
launchDataDispatchGroup.leave() | |
// whatever you want to do with the response | |
} | |
// Timeout for 3 seconds | |
let waitResult: DispatchTimeoutResult = launchDataDispatchGroup.wait(timeout: .now() + .seconds(3)) | |
DispatchQueue.main.async { [weak self] in | |
switch waitResult { | |
case .success: | |
// API calls before 3 second timeout | |
case .timedOut: | |
// APIs timedout | |
} | |
// required instruction | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment