Skip to content

Simple add only async task queue with concurrency support

License

Notifications You must be signed in to change notification settings

trashify/conqueue

Repository files navigation

conqueue

Simple add only async task queue with concurrency support


Built with ❤︎ by tiaanduplessis and contributors

Table of Contents

Table of Contents
  • Install
  • Usage
  • Contribute
  • License
  • Install

    $ npm install @tiaanduplessis/conqueue
    # OR
    $ yarn add @tiaanduplessis/conqueue

    Usage

    const Conqueue = require('conqueue')
    
    const tasks = new Conqueue(2) // Allow 2 tasks to be done concurrently
    
    const a = () =>
      new Promise(resolve =>
        setTimeout(() => {
          console.log('a - done')
          resolve(1)
        }, 1000)
      )
    const b = () =>
      new Promise(resolve =>
        setTimeout(() => {
          console.log('b - done')
          resolve(2)
        }, 2000)
      )
    const c = () => {
      console.log('c - done')
      return 3
    }
    
    const d = () =>
      new Promise(resolve =>
        setTimeout(() => {
          console.log('d - done')
          resolve(4)
        }, 5000)
      )
    const e = () =>
      new Promise(resolve =>
        setTimeout(() => {
          console.log('e - done')
          resolve(5)
        }, 3000)
      )
    const f = () => {
      console.log('f - done')
      return 36
    }
    
    tasks.add(a).add(b).add(c).add(d).add(e).add(f)
    // or
    tasks.add([a, b, c, d, e, f])
    
    // a - done
    // c - done
    // b - done
    // e - done
    // f - done
    // a - done
    // d - done
    // c - done
    // b - done
    // e - done
    // f - done
    // d - done

    Contributing

    Contributions are welcome!

    1. Fork it.
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request :D

    Or open up a issue.

    License

    Licensed under the MIT License.

    About

    Simple add only async task queue with concurrency support

    Topics

    Resources

    License

    Stars

    Watchers

    Forks

    Packages

    No packages published