镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

worker: process.argv for workers #30531

Description

@legendecas

Is your feature request related to a problem? Please describe.
process.argv is commonly used in Node.js. Right now there is only execArgv for altering how node instance works, which will be filtered process.argv with these only Node.js understands.

Describe the solution you'd like
Add an option argv to Worker constructor's second argument.

new Worker(__filename, { argv: ['foo', 'bar'] })
if (!isMainThread) {
  console.log(process.argv) // ['foo', 'bar']
}

Describe alternatives you've considered
Just use option workerData in Worker constructor's second argument.

Activity

  1. added
    workerIssues and PRs related to the worker_threads module and Worker API.
    on Nov 18, 2019
  2. addaleax commented on Nov 18, 2019

    @addaleax
    Member

    @legendecas Feel free to open a PR with this if you like – I think you can pass it around the same way that we pass workerData.

    I would suggest process.argv to follow the standard format though, i.e. process.argv[0] is the Node.js binary being used and process.argv[1] is the main script name (of the Worker thread, in this case).

  3. legendecas commented on Nov 18, 2019

    @legendecas
    MemberAuthor

    @addaleax 😄 I'd like to. Just open the issue to ask around if it was left there intentionally.

  4. addaleax commented on Nov 18, 2019

    @addaleax
    Member

    @legendecas As far as I am concerned, workerData was intended to be the (far more powerful) alternative that we’d use for worker threads, but I don’t personally see any issue with adding a more main-thread-like process.argv.

  5. added a commit that references this issue on Dec 9, 2019
  6. added a commit that references this issue on Jan 14, 2020
  7. added a commit that references this issue on Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.workerIssues and PRs related to the worker_threads module and Worker API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions