function hydrateHandler(req, res, data, hydrate) {
  return new Promise((resolve, reject) => {
    let finishCalled = false
    const finish = (err, result) => {
      if( finishCalled ) {
        console.warn('Finish already called -- do not return a promise and call the callback from the same hydrate function!')
        return
      }
      finishCalled = true
      if( err ) { reject(err) }
      resolve(result)
    }

    const hydratePromise = hydrate(req, res, data, finish)
    if( typeof hydratePromise.then === 'function' ) {
      hydratePromise.then(result => finish(null, result), err => finish(err))
    }
  })
}
/**
 * A function to handle the hydration process
 * @param  {ExpressResponse} res      Passed-in Express response
 * @param  {Buffer|string}   data     Data coming from cache to be hydrated
 * @param  {Function}        hydrate  Function to invoke on data
 * @return {[Promise]}
 */
A function to handle the hydration process
@param  {ExpressResponse} res      Passed-in Express response
@param  {Buffer|string}   data     Data coming from cache to be hydrated
@param  {Function}        hydrate  Function to invoke on data
@return {[Promise]}
A function to handle the hydration process @param { ExpressResponse } res Passed - in Express response @param { Buffer|string } data Data coming from cache to be hydrated @param { Function } hydrate Function to invoke on data @return { [ Promise ] }
function hydrateHandler(req, res, data, hydrate) {
  return new Promise((resolve, reject) => {
    let finishCalled = false
    const finish = (err, result) => {
      if( finishCalled ) {
        console.warn('Finish already called -- do not return a promise and call the callback from the same hydrate function!')
        return
      }
      finishCalled = true
      if( err ) { reject(err) }
      resolve(result)
    }
    const hydratePromise = hydrate(req, res, data, finish)
    if( typeof hydratePromise.then === 'function' ) {
      hydratePromise.then(result => finish(null, result), err => finish(err))
    }
  })
}
function hydrateHandler ( req , res , data , hydrate ) { return new Promise ( ( resolve , reject ) => { let finishCalled = false const finish = ( err , result ) => { if ( finishCalled ) { console . warn ( 'Finish already called -- do not return a promise and call the callback from the same hydrate function!' ) return } finishCalled = true if ( err ) { reject ( err ) } resolve ( result ) } const hydratePromise = hydrate ( req , res , data , finish ) if ( typeof hydratePromise . then === 'function' ) { hydratePromise . then ( result => finish ( null , result ) , err => finish ( err ) ) } } ) }
A function to handle the hydration process
 @param  {ExpressResponse} res      Passed-in Express response
 @param  {Buffer|string}   data     Data coming from cache to be hydrated
 @param  {Function}        hydrate  Function to invoke on data
 @return {[Promise]}
A function to handle the hydration process @param { ExpressResponse } res Passed - in Express response @param { Buffer|string } data Data coming from cache to be hydrated @param { Function } hydrate Function to invoke on data @return { [ Promise ] }