James Black
05/03/2022, 10:14 PMCannot pass function of type '() async -> Void' to parameter expecting synchronous function type
This is the call in iosMain:
actual suspend fun retrieveCurrentForecastByCity(city: String): MonthlyForecast? {
return weatherRepository.retrieveCurrentForecastByCity(city)
}
This code is the action inside a button, but keeping it simple:
await outfitViewModel.currentWeather(city: city)
let a = outfitViewModel.currentWeatherFlow
I can share the repo, but it doesn't compile right now, but basically I call currentWeather, which is a 'suspend' and everything from there is suspend functions. In Android I can use runBlocking { } and and works.
I am using pod 'KMPNativeCoroutinesAsync', '0.12.2' and targeting iOS 15.
Missed one variable. This all works fine on the Android side and everything after this call is in my shared project.
var currentWeatherFlow = MutableSharedFlow<MainTemperature>(1)
Rick Clephas
05/04/2022, 5:19 AMKMPNativeCoroutinesAsync
.
P.S. you probably shouldn't be using runBlocking
on Android. It's best to launch
a coroutine from a (lifecycle) CoroutineScope instead.James Black
05/05/2022, 1:36 AMRick Clephas
05/05/2022, 5:27 AMTask {
do {
let weather = try await outfitViewModel.currentWeather(city: city)
} catch {
// Handle the error
}
}
Task {
let result = await asyncResult(for: outfitViewModel.currentWeather(city: city)
guard case let .success(weather) = result else { return }
}