src/index.js
function generatePromise (promiseFunctions, contraMethod, silenceErrors) {
  return new Promise((resolve, reject) => {
    // Generate a function that executes the promise function and
    // calls back in a way that the contra library requires
    for (let i in promiseFunctions) {
      let promiseFunction = promiseFunctions[i]

      if (!isFunction(promiseFunction)) {
        return reject(new Error('One of the supplied promise functions is not a function'))
      }

      promiseFunctions[i] = (contraCallback) => {
        promiseFunction()
          .then(data => contraCallback(null, data))
          .catch(err => silenceErrors ? contraCallback(null, null) : contraCallback(err))
      }
    }

    contraMethod(promiseFunctions, (err, results) => {
      if (err) return reject(err)
      resolve(results)
    })
  })
}
function generatePromise (promiseFunctions, contraMethod, silenceErrors) {
  return new Promise((resolve, reject) => {
    // Generate a function that executes the promise function and
    // calls back in a way that the contra library requires
    for (let i in promiseFunctions) {
      let promiseFunction = promiseFunctions[i]

      if (!isFunction(promiseFunction)) {
        return reject(new Error('One of the supplied promise functions is not a function'))
      }

      promiseFunctions[i] = (contraCallback) => {
        promiseFunction()
          .then(data => contraCallback(null, data))
          .catch(err => silenceErrors ? contraCallback(null, null) : contraCallback(err))
      }
    }

    contraMethod(promiseFunctions, (err, results) => {
      if (err) return reject(err)
      resolve(results)
    })
  })
}
function generatePromise ( promiseFunctions , contraMethod , silenceErrors ) { return new Promise ( ( resolve , reject ) => { // Generate a function that executes the promise function and // calls back in a way that the contra library requires for ( let i in promiseFunctions ) { let promiseFunction = promiseFunctions [ i ] if ( ! isFunction ( promiseFunction ) ) { return reject ( new Error ( 'One of the supplied promise functions is not a function' ) ) } promiseFunctions [ i ] = ( contraCallback ) => { promiseFunction ( ) . then ( data => contraCallback ( null , data ) ) . catch ( err => silenceErrors ? contraCallback ( null , null ) : contraCallback ( err ) ) } } contraMethod ( promiseFunctions , ( err , results ) => { if ( err ) return reject ( err ) resolve ( results ) } ) } ) }
Wrap the contra library with a promise, and convert the promise functions into callbacks
Wrap the contra library with a promise and convert the promise functions into callbacks