Skip to content

Commit

Permalink
Remove import & clean
Browse files Browse the repository at this point in the history
  • Loading branch information
nomisRev committed Jul 27, 2021
1 parent 1973233 commit ddbac3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlinx.coroutines.flow.map

/**
* Retries collection of the given flow when an exception occurs in the upstream flow based on a decision by the [schedule].
Expand Down Expand Up @@ -123,16 +124,14 @@ public fun fixedRate(
): Flow<Unit> =
if (period == 0L) flowOf(Unit).repeat()
else flow {
val period = period
var lastAwakeAt = timeStampInMillis()

while (true) {
val now = timeStampInMillis()
val next = lastAwakeAt + period

if (next > now) {
val remaining = next - now
delay(remaining)
delay(next - now)
emit(Unit)
lastAwakeAt = next
} else {
Expand All @@ -147,9 +146,9 @@ public fun fixedRate(
}
}

public inline fun <A, B> Flow<A>.mapIndexed(crossinline f: suspend (Int, A) -> B): Flow<B> = flow {
public inline fun <A, B> Flow<A>.mapIndexed(crossinline f: suspend (Int, A) -> B): Flow<B> {
var index = 0
collect { value ->
emit(f(index++, value))
return map { value ->
f(index++, value)
}
}

This file was deleted.

0 comments on commit ddbac3e

Please sign in to comment.