Skip to content
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

Merged
merged 24 commits into from
Mar 17, 2023
Merged

Conversation

nomisRev
Copy link
Member

WIP of new Schedule encoding being worked on in collaboration with @franciscodr

@nomisRev nomisRev requested a review from franciscodr March 14, 2023 16:13
@github-actions
Copy link
Contributor

github-actions bot commented Mar 14, 2023

Copy link
Member

@serras serras left a 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.

Comment on lines 26 to 27
public typealias Next<Input, Output> =
suspend (Input) -> Schedule.Decision<Input, Output>
Copy link
Member

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?

Copy link
Member Author

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.

*/
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> {
Copy link
Member

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.

Comment on lines 405 to 415
): 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()
}
Copy link
Member Author

@nomisRev nomisRev Mar 16, 2023

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 😁 😂

@arrow-kt arrow-kt deleted a comment from rafaparadela Mar 16, 2023
@serras serras mentioned this pull request Mar 16, 2023
@nomisRev nomisRev added the 1.2.0 Tickets belonging to 1.1.2 label Mar 16, 2023
Co-authored-by: Alejandro Serrano <trupill@gmail.com>
@nomisRev
Copy link
Member Author

Thank you so much for these enhancements, and cleaning up the implementation @serras 🧙

@nomisRev nomisRev changed the title [WIP] Schedule encoding New Schedule encoding for Fx Resilience Mar 16, 2023
@nomisRev nomisRev marked this pull request as ready for review March 16, 2023 20:00
Copy link
Collaborator

@franciscodr franciscodr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job with this implementation, @nomisRev and @serras!

@nomisRev nomisRev merged commit 911bf79 into main Mar 17, 2023
@nomisRev nomisRev deleted the sv-improve-schedule-encoding branch March 17, 2023 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.2.0 Tickets belonging to 1.1.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants