const denodeify = require('denodeify')
const resolvePtr = denodeify(require('dns').resolvePtr)
const lookupInstance = require('./lookupInstance')

function discover (/* String */ serviceType, /* Array<String># */ deathInstances) {
  // noinspection JSUnresolvedFunction
  return resolvePtr(serviceType).then(response => {
    // noinspection JSUnresolvedFunction
    return Promise.all(
      response
        .filter(instanceName => !deathInstances || deathInstances.indexOf(instanceName) < 0)
        .map(instanceName =>
          lookupInstance(instanceName)
            .catch(err => err)
            .then(instance => Object.assign({type: serviceType}, instance))
        )
    )
  })
}

module.exports = discover

@@ -673,22 +673,16 @@
       )%0A
-    )%0A
   %7D)%0A%7D%0A%0A

split and add filter for death instances