This code is blocking the UI until the remote config fetch is done. I have put 2 seconds as timeout. Here both completionHandler and after will execute, whichever finishes first.
Will it be ok? Or do I need to take care that only one should execute?
func checkIfRemoteConfigFetched<T>(t:T) -> Promise<T>{
return Promise<T>{ seal in
if self.rConfig?.fetchComplete == true{
seal.fulfill(t)
}
after(seconds: 2).done{
seal.fulfill(t)
}
if let rConfig = self.rConfig{
rConfig.completionHandler = { success in
seal.fulfill(t)
}
}
}
}