mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
worker db edit/update refactor
This commit is contained in:
parent
e2c15f8445
commit
a6ee415c5b
4 changed files with 428 additions and 215 deletions
|
@ -20,6 +20,30 @@ function handleWorkerError(client, err) {
|
|||
pool.destroy(client)
|
||||
}
|
||||
|
||||
// TODO: accuire all workers here, and handle errors so they can be removed if threads exit
|
||||
export function msgAllWorker(data: any): Promise<any> {
|
||||
console.log('MSGING ALL WORKER')
|
||||
return new Promise((resolve) => {
|
||||
const promises = []
|
||||
workers.forEach((worker) => {
|
||||
worker.postMessage(data)
|
||||
console.log('MSGD')
|
||||
promises.push(
|
||||
new Promise((resolve) => {
|
||||
worker.once('message', (msg) => {
|
||||
console.log(worker.index, 'ONCE MESSASGE RESOLVE')
|
||||
resolve(msg)
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
Promise.all(promises).then((res) => {
|
||||
console.log('MSG ALL DONE', res)
|
||||
resolve(res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function doALongTask(obj: any): Promise<any> {
|
||||
if (pool.pending > alertOnPendingCount) {
|
||||
logger.Log(
|
||||
|
@ -91,13 +115,6 @@ export function initWorkerPool(initData: any): void {
|
|||
pool = genericPool.createPool(factory, opts)
|
||||
}
|
||||
|
||||
// TODO: accuire all workers here, and handle errors so they can be removed if threads exit
|
||||
export function msgAllWorker(data: any): void {
|
||||
workers.forEach((worker) => {
|
||||
worker.postMessage(data)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getAWorker(i, initData) {
|
||||
|
@ -140,10 +157,10 @@ function doSomething(client, obj) {
|
|||
const { /* index, */ worker } = client
|
||||
return new Promise((resolve) => {
|
||||
// console.log('[ACCUIRE]: #' + index)
|
||||
worker.postMessage(obj)
|
||||
worker.once('message', (msg) => {
|
||||
resolve(msg)
|
||||
})
|
||||
worker.postMessage(obj)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue