Skip to content
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 macro @throttle #2120

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Add a macro @throttle #2120

wants to merge 1 commit into from

Conversation

mcabbott
Copy link
Member

@mcabbott mcabbott commented Nov 21, 2022

We're discussing removing callbacks in favour of just writing a loop.

One nice thing you can do with callbacks is cb = throttle(mysave, 60) to save roughly once a minute, etc. This PR adds a macro that lets you write @throttle 60 mysave() inside your for-loop. It should accept an arbitrary block of code, which may depend on local variables, e.g.:

for i in 1:100
    g = ...
    @throttle 0.5 begin  # macro creates fun(save, m, g, i) = begin ...
       save("file", m, g, i)
    end
    ...

(It re-uses the function throttle, and has to eval some things to happen before the loop it's in.)

PR Checklist

  • Tests are added
  • Entry in NEWS.md
  • Documentation, if applicable

Copy link

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 71.34%. Comparing base (7be1ca7) to head (e8572ab).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/utils.jl 20.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2120       +/-   ##
===========================================
+ Coverage   34.55%   71.34%   +36.78%     
===========================================
  Files          31       31               
  Lines        1904     1965       +61     
===========================================
+ Hits          658     1402      +744     
+ Misses       1246      563      -683     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant