Orhan Tozan
04/01/2020, 8:15 AMArtyom Degtyarev [JB]
04/01/2020, 8:21 AMribesg
04/01/2020, 8:35 AMOrhan Tozan
04/01/2020, 8:44 AMribesg
04/01/2020, 9:23 AMOrhan Tozan
04/01/2020, 9:38 AMribesg
04/01/2020, 9:39 AMOrhan Tozan
04/01/2020, 9:43 AMribesg
04/01/2020, 9:43 AMsuspend
keyword in Swift, that’s all. Now see the API of Flow. You could use it with callbacks, yesOrhan Tozan
04/01/2020, 9:50 AMSam
04/01/2020, 2:16 PMOrhan Tozan
04/01/2020, 2:29 PMSam
04/01/2020, 2:45 PMOrhan Tozan
04/01/2020, 2:54 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>) { .. }
does the same as
withContext(Dispatchers.Main) { .. }
on iOS?Sam
04/01/2020, 6:10 PMactual open class CoroutineDispatchProvider {
actual open val app: CoroutineDispatcher
get() = applicationDispatcher
actual open val io: CoroutineDispatcher
get() = applicationDispatcher //When coroutines can execute on a background thread in native change this to <http://Dispatchers.IO|Dispatchers.IO>
}
internal actual val applicationDispatcher: CoroutineDispatcher = NsQueueDispatcher(dispatch_get_main_queue())
internal class NsQueueDispatcher(
private val dispatchQueue: dispatch_queue_t
) : CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
dispatch_async(dispatchQueue) {
block.run()
}
}
}
Orhan Tozan
04/01/2020, 6:11 PMribesg
04/02/2020, 8:57 AMDispatchers.*
on iOS because it doesn’t work. You need to make a custom “main thread dispatcher”. Here’s ours:Orhan Tozan
04/02/2020, 11:47 AMribesg
04/02/2020, 12:21 PMOrhan Tozan
04/02/2020, 12:46 PMval scope = MainScope()
fun foo() {
scope.launch {
repeat(1000) {
delay(100)
println("")
}
}
}
ios swift:
foo()
This just works on iOS, doesn it? So whats the difference to do this with your uidispatcher or notribesg
04/03/2020, 10:04 AMMainScope
is a JVM UI thing (Android, JavaFX, Swing)