clj-commons / manifold

A compatibility layer for event-driven abstractions
1.02k stars 106 forks source link

periodically has a random initially delay #94

Open shmish111 opened 8 years ago

shmish111 commented 8 years ago

Why does periodically have a random initial delay (less than the period) if none is provided?

(- period (rem (System/currentTimeMillis) period))

I assumed that it would default to 0, to me this is very strange.

ztellman commented 8 years ago

Either periodically has a non-deterministic initial delay, or a non-deterministic start time. I thought having all periodic functions with the same period running at more or less the same time would be desirable, but I'm not particularly married to that. Thoughts?

shmish111 commented 8 years ago

Don't quite understand, why would the start time be non-deterministic if initial delay is 0?

vspinu commented 8 years ago

The start is actually deterministic, but because it's undocumented it looks as if it's random. IMHO this is a complementary and potentially quite useful features - your 60sec periods will overlap with 10sec periods every 6th time. 0-delay can always be supplied manually if the user wants so.

vspinu commented 8 years ago

If you are using periodically for logging you will get nice round times which are modulo aligned with the period. So I personally think this feature should stay. It just needs to be documented properly.

ztellman commented 8 years ago

I'll come up with some better documentation, or am happy to take a pull request if you think you can explain it clearly.