index.js
function Knack({ concurrency = 5, interval = 500, onDone = () => {} }={}) {
  const q = new Queue(concurrency, interval, onDone)
  /**
   * @func knack
   * @template T
   * @param {function(...args): Promise<T>} func
   * @returns {function(...args): Promise<T>}
   */
  const knack = function(func, {
    priority = 50,
    onTimeout = timeouts.none,
    timeout = 30e3,
    repeats = 3 }={}) {
    return (...args) => q.task(func, { priority, onTimeout, timeout, repeats }, ...args)
  }
  knack.once = ({
    priority = 50,
    onTimeout = timeouts.none,
    timeout = 30e3,
    repeats = 3 }={}) => (func, ...args) => q.task(func, { priority, onTimeout, timeout, repeats }, ...args)
  knack.isHalt = false
  knack.halt = () => {
    q.tryNext = () => {}
    q.task = () => {}
    knack.isHalt = true
  }
  Object.defineProperty(knack, 'active', {
    get: () => q.active
  })
  Object.defineProperty(knack, 'concurrency', {
    get: () => q.concurrency
    // set: parallel => q.concurrency = parallel
  })
  Object.defineProperty(knack, 'interval', {
    get: () => q.interval
    // set: delay => q.interval = delay
  })
  knack.timeouts = timeouts
  return knack
}
function Knack({ concurrency = 5, interval = 500, onDone = () => {} }={}) {
  const q = new Queue(concurrency, interval, onDone)
  /**
   * @func knack
   * @template T
   * @param {function(...args): Promise<T>} func
   * @returns {function(...args): Promise<T>}
   */
  const knack = function(func, {
    priority = 50,
    onTimeout = timeouts.none,
    timeout = 30e3,
    repeats = 3 }={}) {
    return (...args) => q.task(func, { priority, onTimeout, timeout, repeats }, ...args)
  }
  knack.once = ({
    priority = 50,
    onTimeout = timeouts.none,
    timeout = 30e3,
    repeats = 3 }={}) => (func, ...args) => q.task(func, { priority, onTimeout, timeout, repeats }, ...args)
  knack.isHalt = false
  knack.halt = () => {
    q.tryNext = () => {}
    q.task = () => {}
    knack.isHalt = true
  }
  Object.defineProperty(knack, 'active', {
    get: () => q.active
  })
  Object.defineProperty(knack, 'concurrency', {
    get: () => q.concurrency
    // set: parallel => q.concurrency = parallel
  })
  Object.defineProperty(knack, 'interval', {
    get: () => q.interval
    // set: delay => q.interval = delay
  })
  knack.timeouts = timeouts
  return knack
}
function Knack ( { concurrency = 5 , interval = 500 , onDone = ( ) => { } } = { } ) { const q = new Queue ( concurrency , interval , onDone ) /**
   * @func knack
   * @template T
   * @param {function(...args): Promise<T>} func
   * @returns {function(...args): Promise<T>}
   */ const knack = function ( func , { priority = 50 , onTimeout = timeouts . none , timeout = 30e3 , repeats = 3 } = { } ) { return ( ... args ) => q . task ( func , { priority , onTimeout , timeout , repeats } , ... args ) } knack . once = ( { priority = 50 , onTimeout = timeouts . none , timeout = 30e3 , repeats = 3 } = { } ) => ( func , ... args ) => q . task ( func , { priority , onTimeout , timeout , repeats } , ... args ) knack . isHalt = false knack . halt = ( ) => { q . tryNext = ( ) => { } q . task = ( ) => { } knack . isHalt = true } Object . defineProperty ( knack , 'active' , { get : ( ) => q . active } ) Object . defineProperty ( knack , 'concurrency' , { get : ( ) => q . concurrency // set: parallel => q.concurrency = parallel } ) Object . defineProperty ( knack , 'interval' , { get : ( ) => q . interval // set: delay => q.interval = delay } ) knack . timeouts = timeouts return knack }
Create Queue wrapper

@param {any} [{ concurrency = 5, interval = 500 }={}] options
Create Queue wrapper