Skip to content

Instantly share code, notes, and snippets.

@llinardos
Last active August 19, 2019 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save llinardos/051c8949025656c3e12188d29872bb5e to your computer and use it in GitHub Desktop.
Save llinardos/051c8949025656c3e12188d29872bb5e to your computer and use it in GitHub Desktop.
func startApp() {
onMainDo({
self.activityIndicator.startAnimating()
}, onBackgroundDo: {
let storage = PersistentSecureStorage.shared()
guard let savedToken == storage.token {
return .goToAuth
}
let tokenIsValid = authService.isValidToken(savedToken)
if !tokenIsValid {
let newToken = authService.updateToken()
networking.set(token: newToken)
storage.token = newToken
}
let updatedProfile = profileService.getProfile()
user.profile = updatedProfile
let prefetchedThings = thingsService.getThings()
return .goToHome(prefetchedThings)
}, thenOnMainDo: {
self.activityIndicator.stopAnimating()
switch $0 {
case .goToAuth: presentAuth()
case .goToHome(let prefetchedThings): presentHome(prefetchedThings)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment