Skip to content

Instantly share code, notes, and snippets.

@sav007
sav007 / gist:d5b703556ee96034503f1c923a612f4d
Last active April 21, 2021 17:49
Track native module queue perf
override fun onCreate() {
reactNativeHost.reactInstanceManager.addReactInstanceEventListener {
val nativeModulesMessageQueueThread = ReactContext::class.java.getDeclaredField("mNativeModulesMessageQueueThread")
.apply { isAccessible = true }
.get(it) as MessageQueueThreadImpl
val messageHandlerField = MessageQueueThreadImpl::class.java.getDeclaredField("mHandler")
.apply { isAccessible = true }
@sav007
sav007 / MVI.kt
Created July 23, 2019 04:40
Kotlin MVI
typealias ViewStateReducer<STATE, EVENT> = (STATE, EVENT) -> STATE
typealias SideEffect<EVENT, STATE> = suspend (EVENT, STATE) -> EVENT?
fun <STATE, EVENT> CoroutineScope.viewStateFlow(reduce: ViewStateReducer<STATE, EVENT>) = ViewStateFlow.Builder(
scope = this,
reduce = reduce
)
interface Subscription {
package com.shopify.coroutine.sample
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.runBlocking
import kotlin.coroutines.coroutineContext
fun main(vararg args: String) {
// suspendFunc1() //- won't compile outside coroutine or another suspend function