-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Schedule encoding for Fx Resilience #2979
Conversation
Kover Report
|
…row into sv-improve-schedule-encoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This idea behind this implementation makes a lot of sense: we are at each step deciding what to do next. I have some questions about the way this is represented, but other than that everything looks fine to me.
arrow-libs/fx/arrow-fx-resilience/src/commonMain/kotlin/arrow/fx/resilience/Schedule.kt
Outdated
Show resolved
Hide resolved
public typealias Next<Input, Output> = | ||
suspend (Input) -> Schedule.Decision<Input, Output> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why Schedule
cannot be simply this type alias and we need an additional value class
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question! 🙏
I had the exact same thought last night, and the only downside I could find is that we lose the companion object
that currently exposes the top-level builders.
Having to think of an alternative name like object ScheduleApi
I quite quickly rolled back those changes 😂
All suggestions welcome! I think having it as typealias
would actually be really neat.
arrow-libs/fx/arrow-fx-resilience/src/commonMain/kotlin/arrow/fx/resilience/Schedule.kt
Outdated
Show resolved
Hide resolved
*/ | ||
public abstract fun <B> map(f: (output: Output) -> B): Schedule<Input, B> | ||
/** Transforms every [Output]'ed value of `this` schedule using [transform]. */ | ||
public fun <A> map(transform: suspend (output: Output) -> A): Schedule<Input, A> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going on the same idea than above, I find it a bit confusing that you can map
over a Schedule
to change the result of running the computation.
arrow-libs/fx/arrow-fx-resilience/src/commonMain/kotlin/arrow/fx/resilience/Schedule.kt
Outdated
Show resolved
Hide resolved
arrow-libs/fx/arrow-fx-resilience/src/commonMain/kotlin/arrow/fx/resilience/Schedule.kt
Outdated
Show resolved
Hide resolved
): Decision<Input, C> = when { | ||
this is Done && other is Done -> Done(transform(this.output, other.output)) | ||
this is Done && other is Continue -> other.map { x -> transform(null, x) } | ||
this is Continue && other is Done -> this.map { x -> transform(x, null) } | ||
this is Continue && other is Continue -> | ||
Continue( | ||
transform(this.output, other.output), | ||
combineDuration(this.delay, other.delay) | ||
) { this.next(it).or(other.next(it), transform, combineDuration) } | ||
else -> throw IllegalStateException() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve this change rather the nested when
hell 😁 😂
Co-authored-by: Alejandro Serrano <trupill@gmail.com>
Thank you so much for these enhancements, and cleaning up the implementation @serras 🧙 |
…row into sv-improve-schedule-encoding
…row into sv-improve-schedule-encoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP of new Schedule encoding being worked on in collaboration with @franciscodr