This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChatRoomsFragment : Fragment() { | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
viewModel = ViewModelProviders.of(this, factory).get(ChatRoomsViewModel::class.java) | |
subscribeUi() | |
} | |
private fun subscribeUi() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private inline fun <T> createBatchActor(context: CoroutineContext = CommonPool, | |
parent: Job? = null, | |
maxSize: Int = 100, | |
maxTime: Int = 500, | |
crossinline block: (List<T>) -> Unit): SendChannel<T> { | |
return actor(context, parent = parent) { | |
val batch = ArrayList<T>(maxSize) | |
var deadline = 0L // deadline for sending this batch to callback block | |
while(true) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DebounceLiveData<Source>( | |
private val source: LiveData<Source>, | |
private val debounceMs: Long | |
) : LiveData<Source>(), CoroutineScope { | |
private val job = SupervisorJob() | |
override val coroutineContext: CoroutineContext | |
get() = Dispatchers.Main + job | |
private var debounceJob: Job? = null | |
private val observer = Observer<Source> { source -> |
OlderNewer