Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@reibitto
Copy link
Contributor

@reibitto reibitto commented May 7, 2020

Resolves #3468

This skips any sleep calls so that we can simulate a schedule and get its output instantaneously.

One thing I was considering was making input a LazyList so that passing in infinite input was possible if you wanted to (in that case you would solely rely on your Schedule's end condition). Not sure whether that's needed or not though.

Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

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

Looks great! One thought here is it seems like we really have to different things going on:

  1. We have a combinator to "run" a schedule with a list of inputs.
  2. We have a combinator to replace the clock implementation in a schedule with one that doesn't do delays.

I think it could make sense to split these out. So you could have a noDelay combinator that just modifies the clock to not actually do delays and gives you back a new schedule that you could do whatever you want with. And then you have a run combinator that runs a schedule with a given list of inputs. Then this would just be schedule.noDelay.run(inputs) but would let you use the noDelay schedule for other purposes or run a schedule that actually did use sleeps.

val scheduled = schedule.simulate(List.fill(5)(()))
val expected = List(1.minute, 2.minute, 4.minute, 8.minute, 16.minute)
assertM(scheduled)(equalTo(expected))
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe explicitly add @@ timeout(1.seconds) ?

@reibitto
Copy link
Contributor Author

reibitto commented May 7, 2020

That's a really good idea. I like the idea of separating these into 2 methods.

I made the changes and re-used the run method in all of ScheduleSpec.

@reibitto reibitto changed the title Add Schedule.simulate Add Schedule noDelay and run May 7, 2020
Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

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

Nice!

@adamgfraser adamgfraser merged commit 1116afe into zio:master May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simulate a Schedule

3 participants