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

Proposal: Add default rate limit function #129

Open
Cidan opened this issue Nov 6, 2021 · 2 comments
Open

Proposal: Add default rate limit function #129

Cidan opened this issue Nov 6, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@Cidan
Copy link

Cidan commented Nov 6, 2021

Currently in the documentation, a proposed rate limit function is provided as such:

func rateLimitCallback(lastResponse *helix.Response) error {
    if lastResponse.GetRateLimitRemaining() > 0 {
        return nil
    }

    var reset64 int64
    reset64 = int64(lastResponse.GetRateLimitReset())

    currentTime := time.Now().Unix()

    if currentTime < reset64 {
        timeDiff := time.Duration(reset64 - currentTime)
        if timeDiff > 0 {
            fmt.Printf("Waiting on rate limit to pass before sending next request (%d seconds)\n", timeDiff)
            time.Sleep(timeDiff * time.Second)
        }
    }

    return nil
}

I propose adding this function, sans the print statement, to the core helix library. The user would still have to specify the use of this function, but it would simplify the usage of this library and reduce boiler plate for the end user. As such, a client might instantiate the client like so:

client, err := helix.NewClient(&helix.Options{
    ClientID:      "your-client-id",
    RateLimitFunc: helix.DefaultRateLimit,
})

where helix.DefaultRateLimit is the example function above.

Thoughts?

@nicklaw5
Copy link
Owner

nicklaw5 commented Nov 9, 2021

Happy to accept a PR 🙂

@nicklaw5 nicklaw5 added the enhancement New feature or request label Nov 9, 2021
@Cidan
Copy link
Author

Cidan commented Nov 9, 2021

Reasonable response, I'll go ahead and send one over soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants