H
H
Hanry6542022-04-09 09:51:11
Node.js
Hanry654, 2022-04-09 09:51:11

Is it possible to receive data from the child in other ways?

I run fork

this.bot= child_process.fork(__dirname + '\\..\\bot\\src\\mainChild.js', [ jsonString ]);

Which has "addUser" function, I pass messages to run it inside

index.ts process
async stopBot(username: string) {
    const res = await this.bot.send({
      query: 'deleteUser',
      deleteUser: { username }
    })
  }

  // Как получить ответ функции внутри дочернего процесса в переменной res?


mainChild.ts
interface Message {
    query:  'addUser' | 'deleteUser',
    addUser?: AddUser,
    findUserForServer?: FindUserForServer,
    deleteUser?: DeleteUser
}

const bot = new Bot(JSON.parse(process.argv[2]) as Options)

process.on('message', async (message: Message) => {
  if (message.query === 'deleteUser') {
    if (message.deleteUser)
      return await bot .deleteUser(message.deleteUser.username)
  }
});

How can I get an answer

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question