Skip to content

Commit d67be58

Browse files
nullable since in asFlowWithoutDelays and asTzFlowWithoutDelays
1 parent 171bb68 commit d67be58

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## 2.1.1
44

5+
* `asFlowWithoutDelays` and `asTzFlowWithoutDelays` will have nullable `since` parameters with default to `null`
6+
to avoid any inconsistency of `Flow` idiom.
7+
<details>
8+
<summary>About the reason of changes</summary>
9+
Cold flows should not contain some state by default. So, it was not right to save some `DateTime`/`DateTimeTz`
10+
by default. Now it will not use some external state unless developers will set it manually
11+
</details>
12+
513
## 2.1.0
614

715
* Versions

src/commonMain/kotlin/dev/inmo/krontab/utils/SchedulerFlow.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ import kotlinx.coroutines.isActive
1818
* Will emit all the [KronScheduler.next] as soon as possible. In case [KronScheduler.next] return null, flow will
1919
* be completed
2020
*
21-
* @param since Will be used as the first parameter for [KronScheduler.next] fun
21+
* @param since Will be used as the first parameter for [KronScheduler.next] fun. If passed null, `flow`
22+
* will always start since the moment of collecting start
2223
*/
23-
fun KronScheduler.asTzFlowWithoutDelays(since: DateTimeTz = DateTime.nowLocal()): Flow<DateTimeTz> = flow {
24-
var previous = since
24+
fun KronScheduler.asTzFlowWithoutDelays(since: DateTimeTz? = null): Flow<DateTimeTz> = flow {
25+
var previous = since ?: DateTime.nowLocal()
2526
while (currentCoroutineContext().isActive) {
2627
val next = next(previous) ?: break
2728
emit(next)
@@ -57,10 +58,11 @@ fun KronScheduler.asTzFlow(): Flow<DateTimeTz> = asTzFlowWithDelays()
5758
* Will emit all the [KronScheduler.next] as soon as possible. In case [KronScheduler.next] return null, flow will
5859
* be completed
5960
*
60-
* @param since Will be used as the first parameter for [KronScheduler.next] fun
61+
* @param since Will be used as the first parameter for [KronScheduler.next] fun. If passed null, `flow`
62+
* will always start since the moment of collecting start
6163
*/
62-
fun KronScheduler.asFlowWithoutDelays(since: DateTime = DateTime.now()): Flow<DateTime> = flow {
63-
var previous = since
64+
fun KronScheduler.asFlowWithoutDelays(since: DateTime? = null): Flow<DateTime> = flow {
65+
var previous = since ?: DateTime.now()
6466
while (currentCoroutineContext().isActive) {
6567
val next = next(previous) ?: break
6668
emit(next)

0 commit comments

Comments
 (0)