ifesdjeen / hashed-wheel-timer

High Performance Timer / Scheduler Library compatible with ScheduledExecutorService
Eclipse Public License 1.0
223 stars 43 forks source link

allow scheduling with a 0 millisecond delay? #5

Closed 0xg0nz0 closed 7 years ago

0xg0nz0 commented 7 years ago

It's more correct the way you have it: if minimum precision is 10 milliseconds, then a delay of 0 milliseconds is unachievable, and it's not unreasonable to throw an exception. But requiring anyone who wants to schedule "run as soon as possible" to know the timer wheel's resolution also seems wrong; it might be better to round up to the minimum resolution for delays less than the minimum resolution rather than throwing an exception.

ifesdjeen commented 7 years ago

Thanks for the suggestions! I think all of them make sense. Unfortunately, I might not get to it immediately, so feel free to send a patch if you like.

0xg0nz0 commented 7 years ago

Hi Alex, no worries, I will send you a pull request sometime later this week.

0xg0nz0 commented 7 years ago

Note on this fix: I changed just cases with firstDelay below the resolution -- it still applies for scheduleFixedRate() and scheduleFixedDelay().