Pitch: clock.sleep(for:)

Sure; so stepwise durations are durations between integral instants. So if you have a Step(0) as an instant and a Step(5) as another - the duration between the two would be discretely a set number of steps (perhaps expressible by an integer). The advantage of which is that you can run the clock step wise and advance time in discrete chunks. This can be done with Swift.Duration but lots of care need to be done with making values that are controlled carefully. Using integral steps that are not time based but step based helps the design of testing to suss out race conditions and other such failures.

It is not a "must be this way" but instead something that I've encountered that is really helpful. Both approaches rely on that concept of an immediate clock or a controlled incrementing clock.

On the other side of things with that type of testing; we need to make sure folks are careful using that because it fetches the .now from the clock - which can result in time of check races. Again that isn't a feature killer but something that should be documented clearly so folks are not surprised.

Overall I agree that having this is useful, but id say more so that it is interesting for general ergonomics in the cases where deadlines are not fully needed than say the existential form. (Perhaps that is my bias against the performance impacts of existentials over concrete generic values)

1 Like