Android Kotlin Flows: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Created page with "=Introduction= This is a page to capture anything important about kotlin flows. This very similar to RxJava =Simple Example= <syntaxhighlight lang="kotlin"> fun fred() { val countDownFlow = flow<Int> { val startingValue = 10 var currentValue = startingValue emit(currentValue) while (currentValue > 0) { delay(1000L) currentValue-- emit(currentValue) }..."
 
Line 3: Line 3:
=Simple Example=
=Simple Example=
<syntaxhighlight lang="kotlin">  
<syntaxhighlight lang="kotlin">  
    fun fred() {
fun fred() {
        val countDownFlow = flow<Int> {
  val countDownFlow = flow<Int> {
            val startingValue = 10
    val startingValue = 10
            var currentValue = startingValue
    var currentValue = startingValue
            emit(currentValue)
    emit(currentValue)
            while (currentValue > 0) {
    while (currentValue > 0) {
                delay(1000L)
      delay(1000L)
                currentValue--
      currentValue--
                emit(currentValue)
      emit(currentValue)
            }
        }
     }
     }
  }
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 01:53, 18 March 2025

Introduction

This is a page to capture anything important about kotlin flows. This very similar to RxJava

Simple Example

 
fun fred() {
  val countDownFlow = flow<Int> {
    val startingValue = 10
    var currentValue = startingValue
    emit(currentValue)
    while (currentValue > 0) {
      delay(1000L)
      currentValue--
      emit(currentValue)
    }
  }
}