Skip to content

Instantly share code, notes, and snippets.

@ATizik
ATizik / coroutines_flow.kt
Last active May 6, 2020
Coroutines with Flow example
View coroutines_flow.kt
class UploadFilesUsecase() {
private val MAX_RETRIES = 3L
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
private val atomic = atomic<Flow<File>?>(null)
suspend fun uploadFiles(): Flow<File> {
atomic.value?.let { return it }
val channel = ConflatedBroadcastChannel<File>()
@ATizik
ATizik / coroutines.kt
Created May 6, 2020
Coroutines without Flow example
View coroutines.kt
class UploadFilesUsecase() : BaseObservable<UploadFilesUsecase.Listener>() {
interface Listener {
fun onFilesUploaded()
fun onFilesUploadFailed()
}
private val MAX_RETRIES = 3
private val mutex = Mutex()
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
@ATizik
ATizik / LiveDataExample.kt
Last active Nov 21, 2019
Exposing superclass without backing property
View LiveDataExample.kt
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.*
interface MyViewModelInterface {
val liveData: LiveData<String>
}
class MyViewModel:ViewModel(), MyViewModelInterface {
override val liveData = MutableLiveData<String>()