Example #1
0
    const inlineCSS = $inlineStyleNodes.map(($node) => {
      let id = $node.attr('id')
      const css = $node.attr('style')
      $node.removeAttr('style')

      if (!id) {
        id = `heml-${randomString(5)}`
        $node.attr('id', id)
      }

      return `#${id} {${css}}`
    }).join('\n')
Example #2
0
export async function sendJob(config) {
  if (worker && !worker.childProcess.connected) {
    // Sometimes the worker dies and becomes disconnected
    // When that happens, it seems that there is no way to recover other
    // than to kill the worker and create a new one.
    killWorker()
  }

  // Ensure the worker is started
  startWorker()

  // Expand the config with a unique ID to emit on
  // NOTE: Jobs _must_ have a unique ID as they are completely async and results
  // can arrive back in any order.
  // eslint-disable-next-line no-param-reassign
  config.emitKey = cryptoRandomString(10)

  return new Promise((resolve, reject) => {
    // All worker errors are caught and re-emitted along with their associated
    // emitKey, so that we do not create multiple listeners for the same
    // 'task:error' event
    const errSub = worker.on(`workerError:${config.emitKey}`, ({ msg, stack }) => {
      // Re-throw errors from the task
      const error = new Error(msg)
      // Set the stack to the one given to us by the worker
      error.stack = stack
      errSub.dispose()
      // eslint-disable-next-line no-use-before-define
      responseSub.dispose()
      reject(error)
    })
    const responseSub = worker.on(config.emitKey, (data) => {
      errSub.dispose()
      responseSub.dispose()
      resolve(data)
    })
    // Send the job on to the worker
    try {
      worker.send(config)
    } catch (e) {
      errSub.dispose()
      responseSub.dispose()
      console.error(e)
    }
  })
}
Example #3
0
const getContext = function (options) {
  var prefix = options.prefix || 'eth'
  var name = (options.random || !options.name) ? cryptoRandomString(10).toUpperCase() : options.name
  return prefix.toLowerCase() + '_' + name
}
Example #4
0
 defaultValue: () => cryptoRandomString(24),