I have NetworkProvider which will make api call continuously and also once I received the data i will update the userid. At the same time I will access the userid from other functions.
This is data race condition, can someone help to remove the condition.
`
class NetworkProvider {
public var userID: String
func observeStateChange() {
FIRAuth.auth()?.addStateDidChangeListener({ (auth, authenticatedUser) in
if let user = authenticatedUser {
userID = user.uid
}
}
}
func currentUserID() -> String {
return self.userID
}
}`