index.js
function applyN (fn, opts, ready) {
  var num = opts.num || 0
  var unique = opts.unique

  var arr = []

  fn(opts, onValue)

  function onValue (err, value) {
    if (err) {
      return ready(err)
    }

    if (!unique || arr.indexOf(value) === -1) {
      arr.push(value)
    }

    if (arr.length >= num) {
      return ready(null, arr)
    }

    process.nextTick(function () {
      fn(opts, onValue)
    })
  }
}
function applyN (fn, opts, ready) {
  var num = opts.num || 0
  var unique = opts.unique

  var arr = []

  fn(opts, onValue)

  function onValue (err, value) {
    if (err) {
      return ready(err)
    }

    if (!unique || arr.indexOf(value) === -1) {
      arr.push(value)
    }

    if (arr.length >= num) {
      return ready(null, arr)
    }

    process.nextTick(function () {
      fn(opts, onValue)
    })
  }
}
function applyN ( fn , opts , ready ) { var num = opts . num || 0 var unique = opts . unique var arr = [ ] fn ( opts , onValue ) function onValue ( err , value ) { if ( err ) { return ready ( err ) } if ( ! unique || arr . indexOf ( value ) === - 1 ) { arr . push ( value ) } if ( arr . length >= num ) { return ready ( null , arr ) } process . nextTick ( function ( ) { fn ( opts , onValue ) } ) } }
Creates an array of items, whose contents are the result of calling
asynchronous function fn once for each item in the array. The function is
called in series, until the array is filled.

@param {Function} fn the function to be called with ({Objct} opts, ready)
where `ready` must be called with (err, value)
@param {Object} opts the options hash that random-lib expects
@param {Function} ready the function to be called with (err, {Array} values)
Creates an array of items whose contents are the result of calling asynchronous function fn once for each item in the array . The function is called in series until the array is filled .