repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge dependabot/npm_and_yarn/examples/typescript/websocket-server-pool/ws-hybrid...
[poolifier.git]
/
examples
/
typescript
/
pool.ts
diff --git
a/examples/typescript/pool.ts
b/examples/typescript/pool.ts
index 54b437ab31b2f1d7785439c5ce9007167e554331..57898d98a9d53a8c89c3d774847e9cae694a53fe 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,14
+1,20
@@
-import { join } from 'path'
-import type { MyData, MyResponse } from './worker'
+import { dirname, extname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+import type { MyData, MyResponse } from './worker.js'
import {
DynamicThreadPool,
FixedThreadPool,
availableParallelism
} from 'poolifier'
import {
DynamicThreadPool,
FixedThreadPool,
availableParallelism
} from 'poolifier'
+const workerFile = join(
+ dirname(fileURLToPath(import.meta.url)),
+ `worker${extname(fileURLToPath(import.meta.url))}`
+)
+
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
availableParallelism(),
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
availableParallelism(),
-
join(__dirname, 'worker.js')
,
+
workerFile
,
{
errorHandler: (e: Error) => {
console.error(e)
{
errorHandler: (e: Error) => {
console.error(e)
@@
-22,7
+28,7
@@
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
Math.floor(availableParallelism() / 2),
availableParallelism(),
export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
Math.floor(availableParallelism() / 2),
availableParallelism(),
-
join(__dirname, 'worker.js')
,
+
workerFile
,
{
errorHandler: (e: Error) => {
console.error(e)
{
errorHandler: (e: Error) => {
console.error(e)
@@
-32,3
+38,9
@@
export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
}
}
)
}
}
)
+
+// eslint-disable-next-line @typescript-eslint/no-misused-promises
+setTimeout(async () => {
+ await fixedPool.destroy()
+ await dynamicPool.destroy()
+}, 3000)