Closed robludwig closed 1 year ago
Hello, thanks for the PR.
Personal bias, but metaprogramming kinda creeps me out. That said, I certainly see the value of making sure the function arity is consistent. Perhaps we could use this technique instead?
Object.defineProperty(limiter, "length", { value: fn.length })
Wrote a more detailed explanation here: http://stackoverflow.com/questions/7316688/how-to-programmatically-set-the-length-of-a-function/37645357#37645357
It'd be less code and wouldn't require metaprogramming. The down side is that this trick doesn't work in all versions of node.js which is a bummer. We'd have to wrap the call in a try/catch to make sure we don't break people's existing code. What do you think?
I share your wariness of metaprogramming, and defineProperty
works perfectly for my purposes. I updated the PR to use that instead and did some testing to see which versions it works for. It looks like node with version >= 3 should be fine. Otherwise it fails with a TypeError
. I decided to just catch and discard the error since it doesn't seem hugely important if it fails.
Hi- I fixed this to use defineProperty and to check for errors when doing so. Anything else needed before merging?
LGTM.
Sorry I dropped this on the flow. Thank you!
Fixes #2.
I needed this for a fix of my own. It adds some helpful behavior to the object returned by the rate limiter. It's probably an edge case and not of interest to many but I found it useful.
Tests all pass. I studied the methodology of blakeembrey/arity in crafting the solution.