Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active July 16, 2022 17:24
Show Gist options
  • Select an option

  • Save benigumocom/baea7a91a8d8fc985333678373d382d0 to your computer and use it in GitHub Desktop.

Select an option

Save benigumocom/baea7a91a8d8fc985333678373d382d0 to your computer and use it in GitHub Desktop.
fun <T> Flow<T>.log(label: String, tag: String = "###"): Flow<T> {
val prefix = "$tag [$label] ${this.javaClass.simpleName}"
return this
.onStart {
Timber.d("$prefix onStart()")
}
.onEach { value ->
Timber.d("$prefix onEach() value = $value")
}
.onCompletion { cause ->
Timber.d("$prefix onCompletion() cause = $cause")
}
.onEmpty {
Timber.d("$prefix onEmpty()")
}
}
@benigumocom
Copy link
Copy Markdown
Author

Flow - Search result - android.benigumo.com
👉 https://bit.ly/3ECgzeu

@benigumocom
Copy link
Copy Markdown
Author

【Kotlin】Flow の挙動やライフサイクルをログで確認する
👉 https://android.benigumo.com/20220505/flow-lifecycle/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment