Sangeet
11/05/2018, 5:02 PMdispatch_async_f(...)
kpgalligan
11/05/2018, 5:07 PMSangeet
11/05/2018, 6:13 PMolonho
11/05/2018, 6:37 PMSangeet
11/05/2018, 7:08 PMexecuteAsync
but the thing is I need to invoke higher order function after resultolonho
11/05/2018, 7:39 PMSangeet
11/05/2018, 7:59 PMUncaught Kotlin exception: kotlin.IllegalStateException: Illegal transfer state
at 0 common 0x0000000103b16a76 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 70
at 1 common 0x0000000103b16996 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 70
at 2 common 0x0000000103b23246 kfun:kotlin.IllegalStateException.<init>(kotlin.String?)kotlin.IllegalStateException + 70
at 3 common 0x0000000103b475e2 ThrowWorkerInvalidState + 66
at 4 common 0x0000000103b66f0d Kotlin_Worker_detachObjectGraphInternal + 93
at 5 common 0x0000000103b48233 kfun:kotlin.native.concurrent.DetachedObjectGraph.<init>(kotlin.native.concurrent.TransferMode;kotlin.Function0<#GENERIC>)kotlin.native.concurrent.DetachedObjectGraph<#GENERIC> + 83
at 6 common 0x0000000103b4833a kfun:kotlin.native.concurrent.DetachedObjectGraph.<init>(kotlin.native.concurrent.TransferMode;kotlin.Function0<#GENERIC>;kotlin.Int;kotlin.native.internal.DefaultConstructorMarker)kotlin.native.concurrent.DetachedObjectGraph<#GENERIC> + 186
olonho
11/05/2018, 8:14 PMkpgalligan
11/05/2018, 8:20 PMkpgalligan
11/05/2018, 8:20 PMSangeet
11/05/2018, 8:25 PMexecuteAsync(NSOperationQueue.mainQueue) {
val response = task.response as? NSHTTPURLResponse
Pair(when {
response == null -> QueryResult(null, didCompleteWithError?.localizedDescription)
response.statusCode.toInt() != 200 -> QueryResult(null, "${response.statusCode.toInt()})")
else -> QueryResult(
NSJSONSerialization.JSONObjectWithData(receivedData, 0, null) as? Map<String, *>,
null
)
}, { result: QueryResult ->
block.invoke(result)
})
}
}
}
inline fun <reified T> executeAsync(queue: NSOperationQueue, crossinline producerConsumer: () -> Pair<T, (T) -> Unit>) {
dispatch_async_f(queue.underlyingQueue, DetachedObjectGraph {
producerConsumer()
}.asCPointer(), staticCFunction { it ->
val result = DetachedObjectGraph<Pair<T, (T) -> Unit>>(it).attach()
result.second(result.first)
})
}
kpgalligan
11/05/2018, 8:32 PMkpgalligan
11/05/2018, 8:33 PMSangeet
11/05/2018, 9:06 PMSangeet
11/05/2018, 9:15 PMfeeze()
for return of data
inline fun <reified T> executeAsync(queue: NSOperationQueue, crossinline producerConsumer: () -> Pair<T, (T) -> Unit>) {
dispatch_async_f(queue.underlyingQueue, DetachedObjectGraph {
// added freeze() here
producerConsumer().freeze()
}.asCPointer(), staticCFunction { it ->
val result = DetachedObjectGraph<Pair<T, (T) -> Unit>>(it).attach()
result.second(result.first)
})
}
This has solved all the problems
@kpgalligan Can you help me with any document which describes about freeze()
so that I could understand it well.kpgalligan
11/05/2018, 9:22 PMkpgalligan
11/05/2018, 9:23 PMkpgalligan
11/05/2018, 9:23 PMkpgalligan
11/05/2018, 9:24 PMkpgalligan
11/05/2018, 9:24 PMkpgalligan
11/05/2018, 9:24 PMkpgalligan
11/05/2018, 9:26 PMkpgalligan
11/05/2018, 9:26 PMSangeet
11/05/2018, 9:29 PMkpgalligan
11/05/2018, 9:30 PMSangeet
11/05/2018, 9:32 PM