I did a lot of research and haven't got any answer for this one.
this is my code:
fileprivate var dispose: ScopedDisposable<AnyDisposable>?
func connectToServer() {
...
let user = ...
let channelName = getChannelName(user)
self.connector.connectTo(channelName)
}
func getChannelName(_ user: String) -> String {
var channelName: String = ""
self.dispose = ScopedDisposable(
self.service.requestChannelNameFromServerForUser(user)
.startWithValues({ results in
channelName = results[0].channelName
})
)
return channelName // this will return "" because callback hasn't returned yet
}
I'm trying to find a way to make the function "getChannelName" to wait until "channelName" is retrieved from the reactive request (from another server).
Thanks for your help.
The
first()function will essentially do this for you:But the more idiomatic way to do this is to make
connectToServeritself an asynchronousSignalProducerwhich connects thegetChannelNameandconnectToproducers into one one larger producer.