requestRemoteNode = (url, headers, tmpFilename, httpOpts, attempt = 1) =>
  new Promise((resolve, reject) => {
    let timeout

    // Called if we stall without receiving any data
    const handleTimeout = async () => {
      fsWriteStream.close()
      fs.removeSync(tmpFilename)
      if (attempt < STALL_RETRY_LIMIT) {
        // Retry by calling ourself recursively
        resolve(
          requestRemoteNode(url, headers, tmpFilename, httpOpts, attempt + 1)
        )
      } else {
        processingCache[url] = null
        totalJobs -= 1
        bar.total = totalJobs
        reject(
          new Error(
            `Failed to download ${url} after ${STALL_RETRY_LIMIT} attempts`
          )
        )
      }
    }

    const resetTimeout = () => {
      if (timeout) {
        clearTimeout(timeout)
      }
      timeout = setTimeout(handleTimeout, STALL_TIMEOUT)
    }

    const responseStream = got.stream(url, {
      headers,
      timeout: { send: CONNECTION_TIMEOUT },
      ...httpOpts,
    })
    const fsWriteStream = fs.createWriteStream(tmpFilename)
    responseStream.pipe(fsWriteStream)

    // If there's a 400/500 response or other error.
    responseStream.on(`error`, error => {
      if (timeout) {
        clearTimeout(timeout)
      }
      processingCache[url] = null
      totalJobs -= 1
      bar.total = totalJobs
      fs.removeSync(tmpFilename)
      console.error(error)
      reject(error)
    })

    fsWriteStream.on(`error`, error => {
      if (timeout) {
        clearTimeout(timeout)
      }
      processingCache[url] = null
      totalJobs -= 1
      bar.total = totalJobs
      reject(error)
    })

    responseStream.on(`response`, response => {
      resetTimeout()

      fsWriteStream.on(`finish`, () => {
        if (timeout) {
          clearTimeout(timeout)
        }
        resolve(response)
      })
    })
  })
requestRemoteNode
--
Download the requested file

@param  {String}   url
@param  {Headers}  headers
@param  {String}   tmpFilename
@param  {Object}   httpOpts
@param  {number}   attempt
@return {Promise<Object>}  Resolves with the [http Result Object]{@link https://nodejs.org/api/http.html#http_class_http_serverresponse}