mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Adding questions using worker pools
This commit is contained in:
parent
d8695682f7
commit
4681ea3791
5 changed files with 50 additions and 17 deletions
src/utils
|
@ -18,7 +18,7 @@ let workers: any = null
|
|||
// console.log('[MSGFROMCLIENT]', res)
|
||||
// })
|
||||
|
||||
export function doALongTask(i: Number, obj: any): Promise<any> {
|
||||
export function doALongTask(obj: any): Promise<any> {
|
||||
return new Promise((resolve) => {
|
||||
pool
|
||||
.acquire()
|
||||
|
@ -47,11 +47,12 @@ export function initWorkerPool(): void {
|
|||
workers = []
|
||||
const factory = {
|
||||
create: function() {
|
||||
const worker = getAWorker(workers.length)
|
||||
const currInd = workers.length
|
||||
const worker = getAWorker(currInd)
|
||||
workers.push(worker)
|
||||
return {
|
||||
worker: worker,
|
||||
index: workers.length,
|
||||
index: currInd,
|
||||
}
|
||||
},
|
||||
destroy: function(client) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue