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/http-client-pool/poolifier-3.1...
[poolifier.git]
/
examples
/
typescript
/
pool.ts
diff --git
a/examples/typescript/pool.ts
b/examples/typescript/pool.ts
index 869e62a8bf718020c155ae221b85921735a61d74..de49c93ad6f8c73bc3cfaa680a78134cdd8daa56 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,10
+1,20
@@
-import { join } from 'path'
+import { dirname, extname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
import type { MyData, MyResponse } from './worker'
import type { MyData, MyResponse } from './worker'
-import { DynamicThreadPool, FixedThreadPool } 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>>(
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
-
8
,
-
join(__dirname, 'worker.js')
,
+
availableParallelism()
,
+
workerFile
,
{
errorHandler: (e: Error) => {
console.error(e)
{
errorHandler: (e: Error) => {
console.error(e)
@@
-16,9
+26,9
@@
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
)
export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
)
export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
-
2
,
-
8
,
-
join(__dirname, 'worker.js')
,
+
Math.floor(availableParallelism() / 2)
,
+
availableParallelism()
,
+
workerFile
,
{
errorHandler: (e: Error) => {
console.error(e)
{
errorHandler: (e: Error) => {
console.error(e)
@@
-28,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)