Open frankie-zeng opened 5 months ago
If I understand you correctly you would like to be able to send an event from a worker to the main thread? There already is a way to send an event (like progress) from the worker to the main thread using the exec
option { on: (payload: any) => void }
. Is that what you mean?
like this.
const pool=...
pool.on('xxx")
worker.workerEmit in anywhere, not only in function
Ah, ok so you would like to call worker.workerEmit()
outside of a function. We can think that through. Two questions:
Hi, josdejong,
/* always import uds first*/
import { workerEmit } from 'workerpool'
import {uds} from './lib/uds'
import * as fs from 'fs'
//it can't work in current version console.log('started')
//it can't work in current version workerEmit({register:'JobFunction0'})
uds.on('Seq:DiagnosticSessionControl16:preSend',async function (val){ //it doesn't support async function await workerEmit({event:'Seq:DiagnosticSessionControl16:recv',data:Buffer.from('')}) await workerEmit({event:'Seq:DiagnosticSessionControl16:recv',data:Buffer.from('')})
//it need wait main done the event then return
return
})
onCreateWorker
to allow for that? Or is the current functionality of onCreateWorker
already sufficient for what you need?sure, and maybe we can add promiseMap in worker side to imple async emit like main side. thanks.
when the worker counte is one (min:1,max:1), woker should can emit event outside function, pool can on('event') global.