Skip to content

Instantly share code, notes, and snippets.

View brendanw's full-sized avatar

Brendan brendanw

View GitHub Profile
@brendanw
brendanw / IPlainClient.kt
Last active April 21, 2020 00:19
A hacky means for making api calls with coroutines-native-mt while we wait for ktor bugs to get fixed.
/**
* An http client to use until ktor works with multithreaded coroutines.
* This goes in a common module that ios and android clients depend on.
* We just return a string as shared components can use kotlinx serialization
* thereafter to handle response parsing.
*/
interface IPlainClient {
fun get(
baseUrl: String,
path: String,
open class BaseViewModel<T : Any, R : Any>(
initialState: T
) : CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext = Dispatchers.Main + job
protected val _state = ConflatedBroadcastChannel<T>(initialState)
val state = _state.asFlow()
val cState = state.wrap()