Grzegorz Sagadyn
10/08/2020, 9:15 AM########### make call
first
second
Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared AsyncCalc.$makeCall$lambda-0$FUNCTION_REFERENCE$0@9d0328 from other thread
Kotlin Code:
interface ApiCall {
fun get(url: String, success: (String) -> Unit)
}
class AsyncCalc(private val apiCall: ApiCall) {
fun makeCall() {
apiCall.freeze()
println("########### make call")
apiCall.get("<http://www.example.com|www.example.com>") {
println("########### $it")
}.freeze()
}
}
iOS impl:
let queue = DispatchQueue(label: "com.test.queue")
class ApiCalcImpl: ApiCall {
func get(url: String, success: @escaping (String) -> Void) {
print("first")
queue.async {
print("second")
success("hello")
print("third")
}
}
}
@main
internal class AppDelegate: UIResponder, UIApplicationDelegate {
let test = ApiCalcImpl()
internal func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
AsyncCalc(apiCall: test).makeCall()
return true
}
...
Kris Wong
10/08/2020, 1:05 PMapiCall.get("<http://www.example.com|www.example.com>", {
println("########### $it")
}.freeze())
Grzegorz Sagadyn
10/08/2020, 1:23 PMKris Wong
10/08/2020, 1:29 PMKris Wong
10/08/2020, 1:31 PM