Adding questions using worker pools

This commit is contained in:
mrfry 2020-12-19 10:32:15 +01:00
parent d8695682f7
commit 4681ea3791
5 changed files with 50 additions and 17 deletions

View file

@ -585,7 +585,6 @@ const workerTs = (file: string, wkOpts: any) => {
if (!isMainThread) {
const workerIndex = workerData.workerIndex
// TODO: check if thread independent
logger.Log(
`[THREAD #${workerIndex}]: Worker ${workerIndex} reporting for duty`
@ -595,7 +594,11 @@ if (!isMainThread) {
if (msg.type === 'work') {
const { qdb, subjName, question, questionData } = msg.data
const index = msg.index
console.log(`[THREAD #${workerIndex}]: staring work on ${index}`)
console.log(
`[THREAD #${workerIndex}]: staring work${
!isNaN(index) ? ` on job index #${index}` : ''
}`
)
let searchResult = null
try {
@ -607,12 +610,18 @@ if (!isMainThread) {
// ONDONE:
parentPort.postMessage({
msg: `From thread #${workerIndex}: job ${index} done`,
msg: `From thread #${workerIndex}: job ${
!isNaN(index) ? `#${index}` : ''
}done`,
workerIndex: workerIndex,
result: searchResult,
})
console.log(`[THREAD #${workerIndex}]: Work ${index} done!`)
console.log(
`[THREAD #${workerIndex}]: Work ${
!isNaN(index) ? `#${index}` : ''
}done!`
)
} else if (msg.type === 'update') {
if (msg.data.workerIndex !== workerIndex) {
// TODO