return { ok: 1 }
}
-class MyWorker extends ThreadWorker {
- constructor () {
- super(yourFunction, { maxInactiveTime: 1000 * 60})
- }
-}
-module.exports = new MyWorker()
+module.exports = new ThreadWorker(yourFunction, { maxInactiveTime: 60000 })
```
-Instantiate your pool based on your needed :
+Instantiate your pool based on your needed :
```js
'use strict'
return { ok: 1 }
}
-class MyWorker extends ThreadWorker {
- constructor () {
- super(yourFunction)
- }
-}
-module.exports = new MyWorker()
+module.exports = new ThreadWorker(yourFunction)
}
}
-class MyWorker extends ThreadWorker {
- constructor () {
- super(yourFunction)
- }
-}
-module.exports = new MyWorker()
+module.exports = new ThreadWorker(yourFunction)
return { ok: 1 }
}
-class MyWorker extends ThreadWorker {
- constructor () {
- super(yourFunction)
- }
-}
-module.exports = new MyWorker()
+module.exports = new ThreadWorker(yourFunction)
}
}
- destroy () {
+ async destroy () {
for (const worker of this.workers) {
- worker.terminate()
+ await worker.terminate()
}
}
closedThreads++
})
})
- pool.destroy()
- await new Promise(resolve => setTimeout(resolve, 2000))
+ await pool.destroy()
expect(closedThreads).toBe(min)
})
closedThreads++
})
})
- pool.destroy()
- await new Promise(resolve => setTimeout(resolve, 1000))
+ await pool.destroy()
expect(closedThreads).toBe(numThreads)
})
return data
}
-class MyWorker extends ThreadWorker {
- constructor () {
- super(echo, { maxInactiveTime: 500 })
- }
-}
-
-module.exports = new MyWorker()
+module.exports = new ThreadWorker(echo, { maxInactiveTime: 500 })
function test (data) {
}
-class MyWorker extends ThreadWorker {
- constructor () {
- super(test, { maxInactiveTime: 500 })
- }
-}
-
-module.exports = new MyWorker()
+module.exports = new ThreadWorker(test, { maxInactiveTime: 500 })
throw new Error(data)
}
-class MyWorker extends ThreadWorker {
- constructor () {
- super(error, { maxInactiveTime: 500 })
- }
-}
-
-module.exports = new MyWorker()
+module.exports = new ThreadWorker(error, { maxInactiveTime: 500 })
return isMainThread
}
-class MyWorker extends ThreadWorker {
- constructor () {
- super(test, { maxInactiveTime: 500 })
- }
-}
-
-module.exports = new MyWorker()
+module.exports = new ThreadWorker(test, { maxInactiveTime: 500 })