Skip to content
This repository has been archived by the owner on Aug 24, 2019. It is now read-only.

Adding block parameter to DebouncedLimiter.execute? #31

Open
basememara opened this issue Jun 13, 2017 · 1 comment
Open

Adding block parameter to DebouncedLimiter.execute? #31

basememara opened this issue Jun 13, 2017 · 1 comment

Comments

@basememara
Copy link
Contributor

Great library btw, thanks for sharing this!

I was wondering what the thoughts were behind not providing a block parameter to the execute function of the DebouncedLimiter like TimedLimiter? I wanted to do something like this:

let refreshTimeline = DebouncedLimiter(limit: 5)

refreshTimeline.execute {
    // Do some work that only runs last block per 5 seconds.
}

I have extended this in my fork to do this, but wanted to get your thoughts before creating a PR in case there's something I'm missing: https://github.com/basememara/RateLimit/commit/763a1b60fdc5884b70540cbb1c58aff6874a68b9

@basememara
Copy link
Contributor Author

..Also let's me fully encapsulate debouncers in extensions without stored properties or force unwrapping:

extension ViewController {
    private static var refreshTimelineLimiter = DebouncedLimiter(limit: 5)
    
    func refreshTimeline() {
        ViewController.refreshTimelineLimiter.execute {
            // Do some work that only runs last block per 5 seconds.
        }
    }
}

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

No branches or pull requests

1 participant