Intersect (&)
Intersect returns the intersect of two Schedule. As long as both of the two Schedule are still running it will return the maximum Duration.
Using the Intersect method,
Schedule intersect = Schedule
.Linear(TimeSpan.FromSeconds(1))
.Intersect(Schedule.Spaced(TimeSpan.FromSeconds(3)));
| Duration |
|---|
| 3 seconds |
| 3 seconds |
| 3 seconds |
| 4 seconds |
| 5 seconds |
Using the operator &,
Schedule intersect =
Schedule.Spaced(TimeSpan.FromSeconds(4)).Take(4)
& Schedule.Linear(TimeSpan.FromSeconds(1), factor: 2);
| Duration |
|---|
| 4 seconds |
| 4 seconds |
| 5 seconds |
| 7 seconds |
The returned Schedule will run as long as the shortest of the two Schedule
Schedule leftSideLonger =
Schedule.Spaced(TimeSpan.FromSeconds(4)).Take(4)
& Schedule.Linear(TimeSpan.FromSeconds(1), factor: 2).Take(2);
Assert.Equal(2, leftSideLonger.Count);
Schedule rightSideLonger =
Schedule.Spaced(TimeSpan.FromSeconds(4)).Take(3)
& Schedule.Linear(TimeSpan.FromSeconds(1), factor: 2).Take(4);
Assert.Equal(3, rightSideLonger.Count);
operator & can be used with ScheduleTransformer,
Schedule intersect1 =
Schedule.Spaced(TimeSpan.FromSeconds(4)).Take(4) & Schedule.NoDelayOnFirst;
Assert.Equal(4, intersect1.Count);
Assert.Equal(TimeSpan.Zero, intersect1[0]);
Assert.Equal(TimeSpan.FromSeconds(4), intersect1[1]);
Assert.Equal(TimeSpan.FromSeconds(4), intersect1[2]);
Assert.Equal(TimeSpan.FromSeconds(4), intersect1[3]);
Schedule intersect2 =
Schedule.NoDelayOnFirst & Schedule.Linear(TimeSpan.FromSeconds(1)).Take(4);
Assert.Equal(4, intersect2.Count);
Assert.Equal(TimeSpan.Zero, intersect2[0]);
Assert.Equal(TimeSpan.FromSeconds(2), intersect2[1]);
Assert.Equal(TimeSpan.FromSeconds(3), intersect2[2]);
Assert.Equal(TimeSpan.FromSeconds(4), intersect2[3]);