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
src/utils

View file

@ -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) {