Skip to content

Instantly share code, notes, and snippets.

View udnisap's full-sized avatar

Pasindu Perera udnisap

View GitHub Profile
@udnisap
udnisap / rate_limit.js
Last active November 9, 2019 16:49 — forked from epogue/rate_limit.js
This will make sure(most of the times) the concurrent invocation is handled
/* Extend the Underscore object with the following methods */
// Rate limit ensures a function is never called more than every [rate]ms
// Unlike underscore's _.throttle function, function calls are queued so that
// requests are never lost and simply deferred until some other time
//
// Parameters
// * func - function to rate limit
// * rate - minimum time to wait between function calls
// * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request