jhurliman / node-rate-limiter

A generic rate limiter for node.js. Useful for API clients, web crawling, or other tasks that need to be throttled
MIT License
1.51k stars 135 forks source link

Use global.performance instead of perf_hooks.performance for Node >16 #93

Open kevinyou opened 1 year ago

kevinyou commented 1 year ago

Currently, this library uses the just-performance polyfill to get current time: https://github.com/jhurliman/node-rate-limiter/blob/25a866d/src/clock.ts

And that polyfill loads performance from perf_hooks: https://github.com/jhurliman/just-performance/blob/main/src/node.ts

As of node v16, performance is directly exposed under global.performance - https://github.com/nodejs/node/pull/37970

One benefit of this change is that popular library @sinonjs/fake-timers only overrides the global performance object, and not perf_hooks.performance. So right now, users of this library need to explicitly mock out perf_hooks.performance (or just-performance.performance).