repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build(deps-dev): bump @types/node
[poolifier.git]
/
examples
/
typescript
/
pool.ts
diff --git
a/examples/typescript/pool.ts
b/examples/typescript/pool.ts
index 7268ebdc599cfaf6a8951583c5d06d1ced71f9c3..93774422b4500459715ec236c136c1601f13add4 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,30
+1,40
@@
-import { join } from 'path'
+import { dirname, extname, join } from 'path'
+import { fileURLToPath } from '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)
},
onlineHandler: () => {
{
errorHandler: (e: Error) => {
console.error(e)
},
onlineHandler: () => {
- console.
log
('Worker is online')
+ console.
info
('Worker is online')
}
}
)
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)
},
onlineHandler: () => {
{
errorHandler: (e: Error) => {
console.error(e)
},
onlineHandler: () => {
- console.
log
('Worker is online')
+ console.
info
('Worker is online')
}
}
)
}
}
)