Skip to content

Commit 74899b5

Browse files
committed
refactor: make pool destroy() more robust
Signed-off-by: Jérôme Benoit <[email protected]>
1 parent 2cca7b7 commit 74899b5

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

deno.json

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"version": "0.5.11",
44
"exports": "./src/mod.ts",
55
"compilerOptions": {
6-
"lib": [
7-
"deno.worker"
8-
],
6+
"lib": ["deno.worker"],
97
"strict": true
108
},
119
"tasks": {
@@ -27,9 +25,7 @@
2725
"documentation": "deno doc ./src/mod.ts"
2826
},
2927
"test": {
30-
"include": [
31-
"./tests/**/*.test.mjs"
32-
]
28+
"include": ["./tests/**/*.test.mjs"]
3329
},
3430
"fmt": {
3531
"semiColons": false,
@@ -42,18 +38,8 @@
4238
"@std/testing": "jsr:@std/testing@^1.0.15"
4339
},
4440
"publish": {
45-
"include": [
46-
"LICENSE",
47-
"README.md",
48-
"deno.json",
49-
"src/**/*.ts"
50-
]
41+
"include": ["LICENSE", "README.md", "deno.json", "src/**/*.ts"]
5142
},
5243
"lock": false,
53-
"exclude": [
54-
"./coverage",
55-
"./dist/browser",
56-
"./dist/esm",
57-
"./npm"
58-
]
44+
"exclude": ["./coverage", "./dist/browser", "./dist/esm", "./npm"]
5945
}

src/pools/abstract-pool.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,20 +1323,31 @@ export abstract class AbstractPool<
13231323
throw new Error('Cannot destroy an already destroying pool')
13241324
}
13251325
this.destroying = true
1326-
await Promise.all(
1327-
this.workerNodes.map(async (_, workerNodeKey) => {
1328-
await this.destroyWorkerNode(workerNodeKey)
1329-
}),
1330-
)
1331-
if (this.eventTarget != null) {
1332-
this.eventTarget.dispatchEvent(
1333-
new CustomEvent<PoolInfo>(PoolEvents.destroy, { detail: this.info }),
1326+
try {
1327+
await Promise.allSettled(
1328+
this.workerNodes.map(async (_, workerNodeKey) => {
1329+
try {
1330+
await this.destroyWorkerNode(workerNodeKey)
1331+
} catch (error) {
1332+
if (this.eventTarget != null) {
1333+
this.eventTarget.dispatchEvent(
1334+
new ErrorEvent(PoolEvents.error, { error }),
1335+
)
1336+
}
1337+
}
1338+
}),
13341339
)
1335-
this.readyEventEmitted = false
1340+
} finally {
1341+
if (this.eventTarget != null) {
1342+
this.eventTarget.dispatchEvent(
1343+
new CustomEvent<PoolInfo>(PoolEvents.destroy, { detail: this.info }),
1344+
)
1345+
this.readyEventEmitted = false
1346+
}
1347+
delete this.startTimestamp
1348+
this.destroying = false
1349+
this.started = false
13361350
}
1337-
delete this.startTimestamp
1338-
this.destroying = false
1339-
this.started = false
13401351
}
13411352

13421353
private async sendKillMessageToWorker(

0 commit comments

Comments
 (0)