ivan.savytskyi
02/21/2019, 2:52 AMDroidconKotlin
by Touchlab https://github.com/touchlab/DroidconKotlin/blob/kotlin-1.3.20/sessionize/lib/src/iosMain/kotlin/co/touchlab/sessionize/platform/Functions.kt#L49 it uses ThreadLocal wrapper.
The question why not just do this instead:
override operator fun <T> invoke(query: Database.() -> T, callback: (T) -> Unit) {
worker.execute(TransferMode.SAFE, { QueryTask(database, query, callback).freeze() }) { task ->
val result = task.query(task.database)
dispatch_async_f(
queue = dispatch_get_main_queue(),
context = DetachedObjectGraph { QueryTaskResult(result.freeze(), task.callback) }.asCPointer(),
work = staticCFunction { it: COpaquePointer? ->
initRuntimeIfNeeded()
val result = DetachedObjectGraph<Any>(it).attach() as QueryTaskResult<T>
result.callback(result.result)
}
)
}
}
Am I missing something, and there is something wrong with the code above? It seems workingyshrsmz
02/21/2019, 3:17 AMyshrsmz
02/21/2019, 3:19 AMivan.savytskyi
02/21/2019, 4:02 AMivan.savytskyi
02/21/2019, 4:02 AMJobWrapper(backJob, mainJobHolder).freeze()
.olonho
02/21/2019, 5:00 AMolonho
02/21/2019, 5:01 AMContinuator
solves problem of non-freezing the callbackyshrsmz
02/21/2019, 6:02 AMyshrsmz
02/21/2019, 6:03 AMivan.savytskyi
02/21/2019, 4:30 PMfreeze
operation does for the closure / callback especially if it passed from let’s say swift realm, what implications of freezing passed callback?olonho
02/21/2019, 5:03 PMkpgalligan
02/21/2019, 7:26 PMkpgalligan
02/21/2019, 7:45 PMivan.savytskyi
02/25/2019, 5:45 PM