Skip to content

Instantly share code, notes, and snippets.

@timrijckaert
Created May 5, 2022 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timrijckaert/44177d7a23941d2a2a73316469fd642d to your computer and use it in GitHub Desktop.
Save timrijckaert/44177d7a23941d2a2a73316469fd642d to your computer and use it in GitHub Desktop.
package com.bnppf.easybanking
import arrow.fx.coroutines.Schedule
import io.kotest.core.spec.style.StringSpec
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime
import kotlin.time.TimeMark
import kotlin.time.TimeSource
@OptIn(ExperimentalTime::class)
class ScheduleFx : StringSpec({
"test schedule" {
val mark = TimeSource.Monotonic.markNow()
var counter = 0
val a = Schedule
.spaced<Unit>(2.seconds)
.untilInput<Unit> { mark.elapsedNow() > 10.seconds }
.whileInput<Unit> { input -> counter < 100 }
.logOutput { println("hello $it ${mark.elapsedNow()}") }
.repeatOrElseEither({
counter++
}, { throwable, output ->
throwable
})
println(a)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment