C
C
Coder3212017-09-23 05:24:10
JavaScript
Coder321, 2017-09-23 05:24:10

Is it possible to pass a promise or a function to a child process?

Is it possible to pass a promise or a function to a child process?
PS It seems to me that this can not be done, but suddenly.

const { fork } = require('child_process');
const child = fork('./myModule');

child.send(() => {
   return Promise.resolve({})
})

//in myModule
process.on('message', (func) => {
    func()
        .then(res => {
            process.send(res)
        })
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Kornilov, 2017-09-23
@KorniloFF

callback?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question