Skip to content

Instantly share code, notes, and snippets.

View chao2zhang's full-sized avatar
:octocat:

Chao Zhang chao2zhang

:octocat:
View GitHub Profile
@chao2zhang
chao2zhang / activity_main.xml
Created September 2, 2021 22:46
Hot Flow activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
@chao2zhang
chao2zhang / artifact-spec.json
Created July 28, 2021 20:21
Voyager trunk build failure local experimentation
{
"artifacts": {
"Flagship-debug": {
":artifact:sha1": "file:///Users/cazhang/voyager-android_trunk/Flagship/build/temp-publish/com/linkedin/voyager-android/Flagship-debug/0.675.62-SNAPSHOT/Flagship-debug-0.675.62-SNAPSHOT.aab.sha1",
":artifact:sha256": "file:///Users/cazhang/voyager-android_trunk/Flagship/build/temp-publish/com/linkedin/voyager-android/Flagship-debug/0.675.62-SNAPSHOT/Flagship-debug-0.675.62-SNAPSHOT.aab.sha256",
":artifact:sha512": "file:///Users/cazhang/voyager-android_trunk/Flagship/build/temp-publish/com/linkedin/voyager-android/Flagship-debug/0.675.62-SNAPSHOT/Flagship-debug-0.675.62-SNAPSHOT.aab.sha512",
":ivyfile:sha1": "file:///Users/cazhang/voyager-android_trunk/Flagship/build/temp-publish/com/linkedin/voyager-android/Flagship-debug/0.675.62-SNAPSHOT/Flagship-debug-0.675.62-SNAPSHOT.ivy.sha1",
":ivyfile:sha256": "file:///Users/cazhang/voyager-android_trunk/Flagship/build/temp-publish/com/linkedin/voyager-android
@Test
fun testReexecution() = runBlockingTest {
val source = MutableStateFlow(1)
val liveData = source.flatMapConcat {
flowOf(it, it * 10) // Could be actual network request
}.asLiveData()
val observer = object : Observer<Int> {
var observeHistory = mutableListOf<Int>()
override fun onChanged(t: Int) {
observeHistory.add(t)
@chao2zhang
chao2zhang / FlowLiveDataConversionTest.kt
Last active June 23, 2021 17:39
FlowLiveDataConversionTest
class FlowLiveDataTest {
@Rule
@JvmField
val rule = InstantTaskExecutorRule()
private val testDispatcher = TestCoroutineDispatcher()
@Before
fun setup() {
@chao2zhang
chao2zhang / CoroutineLiveData.kt
Created June 23, 2021 05:07
CoroutineLiveData.kt
@MainThread
fun cancel() {
if (cancellationJob != null) {
error("Cancel call cannot happen without a maybeRun")
}
cancellationJob = scope.launch(Dispatchers.Main.immediate) {
delay(timeoutInMs)
if (!liveData.hasActiveObservers()) {
// one last check on active observers to avoid any race condition between starting
// a running coroutine and cancelation
@MainThread
fun cancel() {
if (cancellationJob != null) {
error("Cancel call cannot happen without a maybeRun")
}
cancellationJob = scope.launch(Dispatchers.Main.immediate) {
delay(timeoutInMs)
if (!liveData.hasActiveObservers()) {
// one last check on active observers to avoid any race condition between starting
// a running coroutine and cancelation
@chao2zhang
chao2zhang / FlowLiveDataConversionTest.kt
Created June 23, 2021 04:48
Test Flow.asLiveData() for hot flow - Fix attempt to use coroutineDispatcher
@Test
fun testDefaultTimeoutInBlock() = runBlockingTest {
val testCoroutineDispatcher = TestCoroutineDispatcher()
val source = MutableStateFlow(1)
val liveData = source.asLiveData(
context = testCoroutineDispatcher
)
val observer = object : Observer<Int> {
var observeHistory = mutableListOf<Int>()
@chao2zhang
chao2zhang / FlowLiveDataConversionTest.kt
Last active June 23, 2021 03:48
Test Flow.asLiveData() for hot flow
@Test
fun testDefaultTimeout() = runBlockingTest {
val source = MutableStateFlow(1)
val liveData = source.asLiveData()
val observer = object : Observer<Int> {
var observeHistory = mutableListOf<Int>()
override fun onChanged(t: Int) {
observeHistory.add(t)
}
@chao2zhang
chao2zhang / 3455.diff
Created April 27, 2021 03:33
3455.diff
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts
index 245bc546a..98067412c 100644
--- a/buildSrc/build.gradle.kts
+++ b/buildSrc/build.gradle.kts
@@ -19,7 +19,7 @@ object Plugins {
const val SHADOW = "6.1.0"
const val VERSIONS = "0.28.0"
const val SONAR = "2.8"
- const val DOKKA = "1.4.10"
+ const val DOKKA = "1.4.32"
@chao2zhang
chao2zhang / result.sarif
Created April 18, 2021 22:56
Updated checkstyle sarif
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"downloadUri": "https://github.com/checkstyle/checkstyle/releases/",
"fullName": "Checkstyle",
"informationUri": "https://checkstyle.org/",