Like Promise.all
, but throttled
- Node.js ≥ 8.9.0
declare function throttledConcurrentActions<X> (count: number, list: Action<X>[]): Promise<X[]>
type Action<X> = (x?: X) => X | Promise<X>
import throttledConcurrentActions from 'throttled-concurrent-actions'
const result = await throttledConcurrentActions(
3,
[
() => 'Sync Example',
async () => 'Async Example',
() => 'Another Sync Example',
async past => ({past}),
past => ({past})
]
)
Result:
[
'Sync Example',
'Async Example',
'Another Sync Example',
{past: 'Sync Example'},
{past: 'Async Example'}
]