mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
if-else to swithc-case
This commit is contained in:
parent
834cacc2c7
commit
ee30410209
1 changed files with 33 additions and 30 deletions
|
@ -61,41 +61,44 @@ async function handleWorkerData() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleMessage(
|
function handleMessage(
|
||||||
qdbs: QuestionDb[],
|
qdbs: QuestionDb[],
|
||||||
msg: TaskObject,
|
msg: TaskObject,
|
||||||
workerIndex: number,
|
workerIndex: number,
|
||||||
setQdbs: (newVal: QuestionDb[]) => void
|
setQdbs: (newVal: QuestionDb[]) => void
|
||||||
) {
|
) {
|
||||||
if (msg.type === 'search') {
|
switch (msg.type) {
|
||||||
await handleSearch(qdbs, msg, workerIndex)
|
case 'search':
|
||||||
} else if (msg.type === 'merge') {
|
return handleSearch(qdbs, msg, workerIndex)
|
||||||
await handleMerge(qdbs, msg, workerIndex)
|
case 'merge':
|
||||||
} else if (msg.type === 'dbEdit') {
|
return handleMerge(qdbs, msg, workerIndex)
|
||||||
await handleDbEdit(qdbs, msg, workerIndex, setQdbs)
|
case 'dbEdit':
|
||||||
} else if (msg.type === 'newQuestions') {
|
return handleDbEdit(qdbs, msg, workerIndex, setQdbs)
|
||||||
await handleNewQuestions(qdbs, msg, workerIndex, setQdbs)
|
case 'newQuestions':
|
||||||
} else if (msg.type === 'newdb') {
|
return handleNewQuestions(qdbs, msg, workerIndex, setQdbs)
|
||||||
await handleNewDb(qdbs, msg, workerIndex, setQdbs)
|
case 'newdb':
|
||||||
} else if (msg.type === 'dbClean') {
|
return handleNewDb(qdbs, msg, workerIndex, setQdbs)
|
||||||
await handleDbClean(qdbs, msg, workerIndex)
|
case 'dbClean':
|
||||||
} else if (msg.type === 'rmQuestions') {
|
return handleDbClean(qdbs, msg, workerIndex)
|
||||||
await handleRmQuestions(qdbs, msg, workerIndex, setQdbs)
|
case 'rmQuestions':
|
||||||
} else if (msg.type === 'sendQuestionsToPeers') {
|
return handleRmQuestions(qdbs, msg, workerIndex, setQdbs)
|
||||||
await handleQuestionsToPeers(qdbs, msg, workerIndex)
|
case 'sendQuestionsToPeers':
|
||||||
} else if (msg.type === 'sendUsersToPeers') {
|
return handleQuestionsToPeers(qdbs, msg, workerIndex)
|
||||||
await handleUsersToPeers(qdbs, msg, workerIndex)
|
case 'sendUsersToPeers':
|
||||||
} else if (msg.type === 'sendUserFilesToPeers') {
|
return handleUsersToPeers(qdbs, msg, workerIndex)
|
||||||
await handleUserFilesToPeers(qdbs, msg, workerIndex)
|
case 'sendUserFilesToPeers':
|
||||||
} else {
|
return handleUserFilesToPeers(qdbs, msg, workerIndex)
|
||||||
logger.Log(`Invalid msg type!`, logger.GetColor('redbg'))
|
default:
|
||||||
console.error(msg)
|
logger.Log(`Invalid msg type!`, logger.GetColor('redbg'))
|
||||||
|
console.error(msg)
|
||||||
|
|
||||||
parentPort.postMessage({
|
parentPort.postMessage({
|
||||||
msg: `From thread #${workerIndex}: Invalid message type (${
|
msg: `From thread #${workerIndex}: Invalid message type (${
|
||||||
(msg as any)?.type
|
(msg as any)?.type
|
||||||
})!`,
|
})!`,
|
||||||
workerIndex: workerIndex,
|
workerIndex: workerIndex,
|
||||||
})
|
})
|
||||||
|
return null
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue