Add a simple method to run a block every X time#4349
Conversation
|
What should it do if a task takes more time then given span? In your implementation it will call |
|
That's a good point, I hadn't thought of that. |
|
why not just run yield in spawn? and not calculate negative? |
| counter = 0 | ||
|
|
||
| spawn do | ||
| every(10.milliseconds) do |i| |
There was a problem hiding this comment.
I would suggest at least tripling all the time spans to even have a chance of this test passing consistently.
There was a problem hiding this comment.
Why? Even 1ms is aeons at computer speeds. if it turns out to be a problem it can probably be increased.
There was a problem hiding this comment.
It appears to pass very consistently on my system (not a single random failure in 1000 test runs). Is this a problem anywhere?
There was a problem hiding this comment.
I was wrong, I tried this on my system and it does fail on relatively minor idle jitter events.
|
FWIW, we can keep this feature in a separete lib https://github.com/hugoabonizio/schedule.cr |
|
I don't think this belongs in the std. |
I haven't received a response to #4255 yet, so I'm not sure if this method actually belongs in the standard library, but this is how I'd implement it, and I'd certainly use this method a lot in my code. Closes #4255.