Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-process-exit in worker_threads #328

Open
lagden opened this issue Jun 23, 2019 · 4 comments

Comments

@lagden
Copy link

commented Jun 23, 2019

Issuehunt badges

Is there a solution for these cases?

image

'use strict'

const {workerData, parentPort} = require('worker_threads')
const debug = require('./debug')
const sleep = require('./sleep')

const {data, seq} = workerData
sleep(3)
  .then(() => {
    // some data processing...
    const res = `modified ${data}`
    parentPort.postMessage(`Data processed - ${seq}: ${res}`)
  })
  .catch(error => {
    debug.error(error)
    process.exit(1)
  })

My worker is waiting for an exit event.

'use strict'

const {Worker} = require('worker_threads')

function runService(service, workerData) {
  return new Promise((resolve, reject) => {
    const worker = new Worker(service, {workerData})
    worker.on('message', resolve)
    worker.on('error', reject)
    worker.on('exit', code => {
      if (code !== 0) {
        reject(new Error(`Worker stopped with exit code ${code}`))
      }
    })
  })
}

module.exports = runService

IssueHunt Summary

Backers (Total: $30.00)

Become a backer now!

Or submit a pull request to get the deposits!

Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

@sindresorhus

This comment has been minimized.

Copy link
Owner

commented Jun 23, 2019

It also allows process.exit() to be called in process.on('', func) event handlers. - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-process-exit.md

I guess we just need to support the worker name there in addition to process.

PR welcome :)

@issuehunt-app

This comment has been minimized.

Copy link

commented Sep 6, 2019

@issuehunt has funded $30.00 to this issue.


@lubien

This comment has been minimized.

Copy link
Contributor

commented Sep 19, 2019

Can I work on this on this weekend?

@sindresorhus

This comment has been minimized.

Copy link
Owner

commented Sep 19, 2019

Yup :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.