matheus-rodrigues00 / utils

✨ Library to commonly used cross-projects utilities methods ✨
17 stars 11 forks source link

Create throttle Method #38

Open matheus-rodrigues00 opened 1 year ago

matheus-rodrigues00 commented 1 year ago

Implement a throttle method that limits the concurrency of executing promise-returning functions to a specified number. Method Signature:

async function throttle<T>(
  promises: (() => Promise<T>)[],
  maxConcurrency: number
): Promise<T[]> {
  // Implementation goes here
}
superbrobenji commented 1 day ago

I have a small package for this issue that I recently made, maybe give it a shot: https://www.npmjs.com/package/asyncrify/v/0.1.19?activeTab=readme

matheus-rodrigues00 commented 1 day ago

@superbrobenji looks great, could you go ahead and implement it?

superbrobenji commented 1 day ago

yea, I'll have an open spot tomorrow after work to tackle it quick

superbrobenji commented 4 hours ago

https://github.com/matheus-rodrigues00/utils/pull/62 Here is the PR for this implementation. Had to do a bit of a workaround to keep alligned with the desired Promise<T[]> return. but works as expected. I made a feature request on asynctify that I'll take on when i have a chance to add this functionality and remove this workaround