repositories
/
poolifier.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
ee99693
)
Throw error if worker was not in tasks
author
Shinigami92
<chrissi92@hotmail.de>
Mon, 8 Feb 2021 16:44:54 +0000
(17:44 +0100)
committer
Shinigami92
<chrissi92@hotmail.de>
Mon, 8 Feb 2021 17:26:53 +0000
(18:26 +0100)
src/fixed.ts
patch
|
blob
|
blame
|
history
diff --git
a/src/fixed.ts
b/src/fixed.ts
index 4317100830e1a94aa19834c4f3764359ac97960d..3ca43cdb1e5e13f0033427e153cdfa80025abca0 100644
(file)
--- a/
src/fixed.ts
+++ b/
src/fixed.ts
@@
-91,7
+91,12
@@
export default class FixedThreadPool<Data = any, Response = any> {
public execute (data: Data): Promise<Response> {
// configure worker to handle message with the specified task
const worker = this._chooseWorker()
public execute (data: Data): Promise<Response> {
// configure worker to handle message with the specified task
const worker = this._chooseWorker()
- this.tasks.set(worker, (this.tasks.get(worker) ?? 0) + 1)
+ const previousWorkerIndex = this.tasks.get(worker)
+ if (previousWorkerIndex !== undefined) {
+ this.tasks.set(worker, previousWorkerIndex + 1)
+ } else {
+ throw Error('Worker could not be found in tasks map')
+ }
const id = ++this._id
const res = this._execute(worker, id)
worker.postMessage({ data: data || _void, _id: id })
const id = ++this._id
const res = this._execute(worker, id)
worker.postMessage({ data: data || _void, _id: id })
@@
-111,7
+116,12
@@
export default class FixedThreadPool<Data = any, Response = any> {
}): void => {
if (message._id === id) {
worker.port2?.removeListener('message', listener)
}): void => {
if (message._id === id) {
worker.port2?.removeListener('message', listener)
- this.tasks.set(worker, (this.tasks.get(worker) ?? 0) - 1)
+ const previousWorkerIndex = this.tasks.get(worker)
+ if (previousWorkerIndex !== undefined) {
+ this.tasks.set(worker, previousWorkerIndex + 1)
+ } else {
+ throw Error('Worker could not be found in tasks map')
+ }
if (message.error) reject(message.error)
else resolve(message.data)
}
if (message.error) reject(message.error)
else resolve(message.data)
}