Skip to content

Commit 0b343c6

Browse files
authored
feat(repeat): add repeat operator & kotlin 1.9.0 (hoc081098#174)
🔥
1 parent c88aaba commit 0b343c6

File tree

16 files changed

+654
-458
lines changed

16 files changed

+654
-458
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
## [Unreleased] - TODO
44

5+
### Changed
6+
57
- Update dependencies
6-
- `Kotlin` to `1.8.22`.
8+
- `Kotlin` to `1.9.0`.
79
- `KotlinX Coroutines` to `1.7.2`.
810
- `Gradle` to `8.2`.
911

12+
### Added
13+
14+
- Add `Flow.repeat` operator.
15+
1016
## [0.6.1] - May 18, 2023
1117

1218
### Changed

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ dependencies {
149149
- [`raceWith`](#racewith--ambwith)
150150
- [`ambWith`](#racewith--ambwith)
151151
- [`pairwise`](#pairwise)
152+
- [`repeat`](#repeat)
152153
- [`retryWhenWithDelayStrategy`](#retrywhenwithdelaystrategy)
153154
- [`retryWhenWithExponentialBackoff`](#retrywhenwithexponentialbackoff)
154155
- [`retryWithExponentialBackoff`](#retrywithexponentialbackoff)
@@ -849,6 +850,51 @@ pairwise: (2, 3)
849850

850851
----
851852

853+
#### repeat
854+
855+
- Similar to [RxJS repeat](https://rxjs.dev/api/index/function/repeat)
856+
857+
Returns a `Flow` that will recollect to the source stream when the source stream completes.
858+
859+
```kotlin
860+
flowFromSuspend {
861+
println("Start collecting...")
862+
863+
Random
864+
.nextInt(0..3)
865+
.also { println("Emit: $it") }
866+
}
867+
.repeat(
868+
delay = 1.seconds,
869+
count = 10
870+
)
871+
.filter { it == 2 }
872+
.take(1)
873+
.collect { println("repeat: $it") }
874+
```
875+
876+
Output:
877+
878+
```none
879+
Start collecting...
880+
Emit: 1
881+
Start collecting...
882+
Emit: 3
883+
Start collecting...
884+
Emit: 1
885+
Start collecting...
886+
Emit: 0
887+
Start collecting...
888+
Emit: 1
889+
Start collecting...
890+
Emit: 3
891+
Start collecting...
892+
Emit: 2
893+
repeat: 2
894+
```
895+
896+
----
897+
852898
#### retryWhenWithDelayStrategy
853899

854900
Retries collection of the given flow when an exception occurs in the upstream flow and the

api/FlowExt.api

+12
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public abstract interface class com/hoc081098/flowext/Event {
8181

8282
public final class com/hoc081098/flowext/Event$Complete : com/hoc081098/flowext/Event {
8383
public static final field INSTANCE Lcom/hoc081098/flowext/Event$Complete;
84+
public fun equals (Ljava/lang/Object;)Z
85+
public fun hashCode ()I
8486
public fun toString ()Ljava/lang/String;
8587
}
8688

@@ -191,6 +193,15 @@ public final class com/hoc081098/flowext/RangeKt {
191193
public static final fun range (II)Lkotlinx/coroutines/flow/Flow;
192194
}
193195

196+
public final class com/hoc081098/flowext/RepeatKt {
197+
public static final fun repeat (Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow;
198+
public static final fun repeat (Lkotlinx/coroutines/flow/Flow;I)Lkotlinx/coroutines/flow/Flow;
199+
public static final fun repeat (Lkotlinx/coroutines/flow/Flow;ILkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow;
200+
public static final fun repeat (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow;
201+
public static final fun repeat-HG0u8IE (Lkotlinx/coroutines/flow/Flow;J)Lkotlinx/coroutines/flow/Flow;
202+
public static final fun repeat-SxA4cEA (Lkotlinx/coroutines/flow/Flow;IJ)Lkotlinx/coroutines/flow/Flow;
203+
}
204+
194205
public final class com/hoc081098/flowext/RetryWhenWithDelayStrategyKt {
195206
public static final fun retryWhenWithDelayStrategy (Lkotlinx/coroutines/flow/Flow;Lcom/hoc081098/flowext/DelayStrategy;Lkotlin/jvm/functions/Function4;)Lkotlinx/coroutines/flow/Flow;
196207
public static final fun retryWhenWithExponentialBackoff-7Q0yyfQ (Lkotlinx/coroutines/flow/Flow;JDJLkotlin/jvm/functions/Function4;)Lkotlinx/coroutines/flow/Flow;
@@ -220,6 +231,7 @@ public final class com/hoc081098/flowext/ThrottleConfiguration : java/lang/Enum
220231
public static final field LEADING Lcom/hoc081098/flowext/ThrottleConfiguration;
221232
public static final field LEADING_AND_TRAILING Lcom/hoc081098/flowext/ThrottleConfiguration;
222233
public static final field TRAILING Lcom/hoc081098/flowext/ThrottleConfiguration;
234+
public static fun getEntries ()Lkotlin/enums/EnumEntries;
223235
public static fun valueOf (Ljava/lang/String;)Lcom/hoc081098/flowext/ThrottleConfiguration;
224236
public static fun values ()[Lcom/hoc081098/flowext/ThrottleConfiguration;
225237
}

build.gradle.kts

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
99
import java.net.URL
1010

1111
plugins {
12-
kotlin("multiplatform") version "1.8.22"
12+
kotlin("multiplatform") version "1.9.0"
1313
id("com.diffplug.spotless") version "6.19.0"
1414
id("maven-publish")
1515
id("com.vanniktech.maven.publish") version "0.25.3"
@@ -49,12 +49,16 @@ kotlin {
4949
}
5050
browser {
5151
testTask {
52-
useMocha()
52+
useMocha {
53+
timeout = "10s"
54+
}
5355
}
5456
}
5557
nodejs {
5658
testTask {
57-
useMocha()
59+
useMocha {
60+
timeout = "10s"
61+
}
5862
}
5963
}
6064
}

0 commit comments

Comments
 (0)