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

worker: parentPort.postMessage fails on undefined value #26122

Closed
legendecas opened this issue Feb 15, 2019 · 1 comment
Closed

worker: parentPort.postMessage fails on undefined value #26122

legendecas opened this issue Feb 15, 2019 · 1 comment

Comments

@legendecas
Copy link
Member

legendecas commented Feb 15, 2019

  • Version: 11.9.0
  • Platform: all
  • Subsystem: worker

parentPort.postMessage fails on assumption of not nil of first argument. Though it's documented as accepting any value.

internal/worker/io.js:65
  if (payload.type !== messageTypes.STDIO_WANTS_MORE_DATA)
              ^

TypeError: Cannot read property 'type' of undefined
    at MessagePort.onmessage (internal/worker/io.js:65:15)

full scripts:

const {
  Worker, isMainThread, parentPort, workerData
} = require('worker_threads')

if (isMainThread) {
    const worker = new Worker(__filename);
    worker.on('message', data => console.log('received worker data', data));
    worker.on('error', err => console.error('worker error:', error));
    worker.on('exit', (code) => {
      if (code !== 0)
        console.error(`Worker stopped with exit code ${code}`);
    })
    return
}

parentPort.postMessage(undefined)
legendecas added a commit to legendecas/node that referenced this issue Feb 17, 2019
addaleax pushed a commit that referenced this issue Feb 17, 2019
Related: #26122

PR-URL: #26123
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax pushed a commit that referenced this issue Feb 17, 2019
Related: #26122

PR-URL: #26123
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
rvagg pushed a commit that referenced this issue Feb 28, 2019
Related: #26122

PR-URL: #26123
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Abolfazl-MI
Copy link

I have this code in my worker file which i trigger but this method dose not sending the selected data to up

 _selectRandomQuestion(){
        // get random number base on the question length
        const randomIndex=Math.floor(Math.random()*this.#match_question.length)
        // storing selected question
        this.#_selectedQuestion=this.#match_question[randomIndex]
        console.log('selected question =>')
        console.log(this.#_selectedQuestion)
        // removing selected question from array
        this.#match_question.splice(randomIndex,1)
        // sends selected question out of worker
        return parentPort.postMessage({
            "E":quizGameEventNames.NEXT_QUESTION,
            "D":{
                "data":{
                    "question":this.#_selectedQuestion
                }
            }
        })
    }
    ```
    the worker.on("message") dosen't get anything why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants