-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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? |
spec/std/concurrent_spec.cr
Outdated
counter = 0 | ||
|
||
spawn do | ||
every(10.milliseconds) do |i| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.