0.1.0 • Published 5 years ago

@delucis/stau v0.1.0

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
5 years ago

@delucis/stau

npm version Build Status Coverage Status Known Vulnerabilities Greenkeeper badge

🚦 Run promises with limited concurrency

Installation

npm install --save @delucis/stau

Usage

stau(functions[, limit = 15])

Resolves when all of the functions have resolved.

  • functions

    Type: Array of async/Promise-returning functions

    The functions to execute with limited concurrency

  • limit

    Type: Number
    Default: 15

    The maximum number of functions to execute at the same time

Example

const stau = require('@delucis/stau')
const delay = require('delay')

const task = t => async () => {
  console.log(`Waiting for: ${t}ms`)
  return delay(t)
}

const tasks = [
  task(3000),
  task(5000),
  task(12000)
]

(async function () {
  await stau(tasks, 2)
    .then(() => console.log('Done waiting!'))
})()

// immediately:
// => Waiting for: 3000ms
// => Waiting for: 5000ms
//
// after 5 seconds:
// => Waiting for: 12000ms
//
// after 17 seconds:
// => Done waiting!