Last active
December 7, 2017 16:15
-
-
Save nderkach/e9e1f12c6a6d2a04b521318b2badec3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private var refreshTimer: Timer? | |
public private(set) var tokenExpiryDate: Date? { | |
didSet { | |
guard let tokenExpiryDate = tokenExpiryDate else { return } | |
let timeToExpire = tokenExpiryDate.timeIntervalSinceNow | |
// try to refresh JWT token before the expiration time | |
let timeToRefresh = Date(timeIntervalSinceNow: timeToExpire * 0.9) | |
refreshTimer = Timer.scheduledTimer(withTimeInterval: timeToRefresh.timeIntervalSinceNow, repeats: false) { _ in | |
AwesomeAPI.login("test", "test", onSuccess: {}, onFailure: { _ in }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment