Skip to content

Commit b2d53e7

Browse files
committed
doc(): clear notes and add examples
1 parent 0403138 commit b2d53e7

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

templates/inc/pages/index/KotlinValues/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
* Problems:
1919
* Problem1: "SimplifyConcurrency.kt:13:43: error: too many arguments for 'suspend fun Flow<*>.collect(): Unit'."
2020
* Solution: refactor `collect { value ->`
21-
* Problem2: "SimplifyConcurrency.kt:14:14: error: cannot infer type for this parameter. Specify it explicitly.onEach { value -> log(start, "Countdown: $value") }^^^^^^"
22-
* Solution: TODO:
2321
* `java -jar outputPathOrName.jar`
2422
* run the application
23+
* | [SimplifyConcurrency.kt](SimplifyConcurrency.kt)
24+
* Problems:
25+
* Problem1: "Error: Unable to initialize main class SimplifyConcurrencyKt. java.lang.NoClassDefFoundError: kotlinx/coroutines/flow/Flow"
26+
* Solution: `java -cp SimplifyConcurrency.jar:kotlinx-coroutines-core-jvm-1.10.2.jar SimplifyConcurrencyKt`

templates/inc/pages/index/KotlinValues/SimplifyConcurrency.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ fun main() = runBlocking {
1616
// 5. cancel a coroutine
1717
waitingJob.cancel()
1818
}
19-
log(start, "Liftoff!") // Execution continues when all
20-
} // coroutines have finished
19+
log(start, "Liftoff!")
20+
}
2121

22-
fun countdownSignals(n: Int, delayMillis: Long): Flow&lt;Int> = flow { // Flow builder
22+
fun countdownSignals(n: Int, delayMillis: Long): Flow<Int> = flow {
2323
for (i in (1..n).reversed()) {
24-
delay(delayMillis) // Delay in emitting signals
25-
emit(i) // Emit the flow element
24+
delay(delayMillis)
25+
emit(i)
2626
}
2727
}
2828

2929
// 2. suspend & resumed later functions
3030
suspend fun waiting(start: Long, delayMillis: Long) {
31-
while (currentCoroutineContext().isActive) { // Check coroutine's context
31+
while (currentCoroutineContext().isActive) {
3232
log(start, "Waiting...")
33-
delay(delayMillis) // Waiting concurrently
33+
delay(delayMillis)
3434
}
3535
}
3636

0 commit comments

Comments
 (0)