Coder Social home page Coder Social logo

fredmorcos / throttle_my_fn Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 0.0 16 KB

A Rust attribute macro to limit a function's number of runs over a specified period of time

License: MIT License

Rust 100.00%
macro macros rate-limiter rate-limiting rust rust-crate rust-lang throttle

throttle_my_fn's People

Contributors

fredmorcos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

throttle_my_fn's Issues

Requires `parking_lot` to be manually imported

Great library! One thing I noticed when implementing this to my project was that the documentation says to just import the throttle_my_fn::throttle; but actually need to also import add parking_lot to dependencies and import it because this library itself is not doing that.

Code doesn't compile if function has 2+ arguments

    #[throttle(1, std::time::Duration::from_millis(1000))]
    fn foo0() {}

    #[throttle(1, std::time::Duration::from_millis(1000))]
    fn foo1(a: i32) {}

    #[throttle(1, std::time::Duration::from_millis(1000))]
    fn foo2(a: i32, b: i32) {}

First two examples work, but 3rd fails with the following:

error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `b`
  --> src/lib.rs:23:21
   |
23 |     fn foo2(a: i32, b: i32) {}
   |              -      ^ expected one of 8 possible tokens
   |              |
   |              help: missing `,`

Not sure why it happens.

mut parameter compilation error

Hello, there was a compilation error when using the mut keyword to modify formal parameters...

pub fn my_fn(mut td: TextDisplay, w: i32, h: i32) -> bool {
...
}

The compile time error is as follows:

error: expected expression
130 |     pub fn my_fn(mut td: TextDisplay, w: i32, h: i32) -> bool {
    |                  ^^^

Hope to support Mut keyword.

Add support for debounce

This crate looks really nice. Would it be complex to add a feature to debounce?

So you wait for the X time and run only the last one when the timeout is reached?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.