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

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