Skip to content

NEW: Chronos provides an easy way to limit X operations per Y time in accuracy of nanoseconds

License

Notifications You must be signed in to change notification settings

kataras/chronos

chronos build statusreport cardgithub issuesgithub closed issuesreleaselearn by examplesdocs

Chronos provides an easy way to limit X operations per Y time in accuracy of nanoseconds. Chronos is a crucial tool when calling external, remote or even internal APIs with rate limits.

📑 Table Of Content

🚀 Installation

The only requirement is the Go Programming Language.

$ go get -u github.com/kataras/chronos

chronos has zero third-party dependencies rathen than the Go's standard library.

Chronos is very simple to use tool, you just declare the maximum operations(max) and in every Y time that those operations are allowed to be executed(per). Chronos has the accuracy of nanoseconds.

You can use chronos#Acquire anywhere you want, but be careful because it waits/blocks for availability to be executed.

import (
    "time"

    "github.com/kataras/chronos"
)

func main() {
    // Allow maximum of 5 MyActions calls
    // per 3 seconds.
    c := chronos.New(5, 3 * time.Second)

    // The below actions will execute immediately.
    MyAction(c)
    MyAction(c)
    MyAction(c)
    MyAction(c)
    MyAction(c)
    // The below action will execute after 3 seconds from the last call
    // or when 3 seconds passed without any c.Acquire call.
    MyAction(c)
}

func MyAction(c *chronos.C) {
    <- c.Acquire()
    // Do something here...
}

The <- c.Acquire() is blocking when needed, no any further actions neeeded by the end-developer.

Helpers

The ext package provides two subpackages; function and http. Navigate there to learn how they can help you.

📖 Learn

The awesome chronos community is always adding new content to learn from, _examples is a great place to get started!

Read the godocs for a better understanding.

👥 Community

Join the welcoming community of fellow chronos developers in rocket.chat

  • Post a feature request or report a bug
  • ⭐ and watch the public repository, will keep you up to date
  • 🌎 publish an article or share a tweet about your personal experience with chronos.

📌 Version

Current: 0.0.1

Read more about Semantic Versioning 2.0.0

🥇 People

The original author of chronos is @kataras, you can reach him via;

List of all Authors

List of all Contributors

License

This software is licensed under the open source 3-Clause BSD License.

You can find the license file here, for any questions regarding the license please contact with me.

About

NEW: Chronos provides an easy way to limit X operations per Y time in accuracy of nanoseconds

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages