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,33 +61,34 @@ async function handleWorkerData() {
|
|||
})
|
||||
}
|
||||
|
||||
async function handleMessage(
|
||||
function handleMessage(
|
||||
qdbs: QuestionDb[],
|
||||
msg: TaskObject,
|
||||
workerIndex: number,
|
||||
setQdbs: (newVal: QuestionDb[]) => void
|
||||
) {
|
||||
if (msg.type === 'search') {
|
||||
await handleSearch(qdbs, msg, workerIndex)
|
||||
} else if (msg.type === 'merge') {
|
||||
await handleMerge(qdbs, msg, workerIndex)
|
||||
} else if (msg.type === 'dbEdit') {
|
||||
await handleDbEdit(qdbs, msg, workerIndex, setQdbs)
|
||||
} else if (msg.type === 'newQuestions') {
|
||||
await handleNewQuestions(qdbs, msg, workerIndex, setQdbs)
|
||||
} else if (msg.type === 'newdb') {
|
||||
await handleNewDb(qdbs, msg, workerIndex, setQdbs)
|
||||
} else if (msg.type === 'dbClean') {
|
||||
await handleDbClean(qdbs, msg, workerIndex)
|
||||
} else if (msg.type === 'rmQuestions') {
|
||||
await handleRmQuestions(qdbs, msg, workerIndex, setQdbs)
|
||||
} else if (msg.type === 'sendQuestionsToPeers') {
|
||||
await handleQuestionsToPeers(qdbs, msg, workerIndex)
|
||||
} else if (msg.type === 'sendUsersToPeers') {
|
||||
await handleUsersToPeers(qdbs, msg, workerIndex)
|
||||
} else if (msg.type === 'sendUserFilesToPeers') {
|
||||
await handleUserFilesToPeers(qdbs, msg, workerIndex)
|
||||
} else {
|
||||
switch (msg.type) {
|
||||
case 'search':
|
||||
return handleSearch(qdbs, msg, workerIndex)
|
||||
case 'merge':
|
||||
return handleMerge(qdbs, msg, workerIndex)
|
||||
case 'dbEdit':
|
||||
return handleDbEdit(qdbs, msg, workerIndex, setQdbs)
|
||||
case 'newQuestions':
|
||||
return handleNewQuestions(qdbs, msg, workerIndex, setQdbs)
|
||||
case 'newdb':
|
||||
return handleNewDb(qdbs, msg, workerIndex, setQdbs)
|
||||
case 'dbClean':
|
||||
return handleDbClean(qdbs, msg, workerIndex)
|
||||
case 'rmQuestions':
|
||||
return handleRmQuestions(qdbs, msg, workerIndex, setQdbs)
|
||||
case 'sendQuestionsToPeers':
|
||||
return handleQuestionsToPeers(qdbs, msg, workerIndex)
|
||||
case 'sendUsersToPeers':
|
||||
return handleUsersToPeers(qdbs, msg, workerIndex)
|
||||
case 'sendUserFilesToPeers':
|
||||
return handleUserFilesToPeers(qdbs, msg, workerIndex)
|
||||
default:
|
||||
logger.Log(`Invalid msg type!`, logger.GetColor('redbg'))
|
||||
console.error(msg)
|
||||
|
||||
|
@ -97,5 +98,7 @@ async function handleMessage(
|
|||
})!`,
|
||||
workerIndex: workerIndex,
|
||||
})
|
||||
return null
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue