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
| public suspend inline fun <T : Closeable?, R> T.useCancellably( | |
| crossinline block: (T) -> R | |
| ): R = suspendCancellableCoroutine { cont -> | |
| cont.invokeOnCancellation { this?.close() } | |
| cont.resume(use(block)) | |
| } |
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
| @Keep | |
| internal class LoggingHandler : AbstractCoroutineContextElement(CoroutineExceptionHandler), | |
| CoroutineExceptionHandler { | |
| override fun handleException(context: CoroutineContext, exception: Throwable) { | |
| Crashlytics.logException(exception) | |
| // Since we don't want to crash and Coroutines will call the current thread's handler, we | |
| // install a noop handler and then reinstall the existing one once coroutines calls the new | |
| // handler. | |
| Thread.currentThread().apply { |
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 StateHolder<T : Any>(state: T) { | |
| private val _liveData = MutableLiveData(state) | |
| val liveData: LiveData<T> get() = _liveData | |
| private var _value: T = state | |
| val value: T get() = _value | |
| fun update(notify: Boolean = true, block: T.() -> T) { | |
| synchronized(LOCK) { | |
| _value = block(value) |
OlderNewer