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/smtp-client-pool/poolifier-2.7...
[poolifier.git]
/
examples
/
typescript
/
pool.ts
diff --git
a/examples/typescript/pool.ts
b/examples/typescript/pool.ts
index c2d0a1b8d1f1ba004993d820f8dcdef28f3bd7aa..3d9d9e6f482723cdb634e98bd02a9bbd46df3314 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,30
+1,40
@@
-import {
join } from '
path'
-import {
DynamicThreadPool, FixedThreadPool } from 'poolifier
'
+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,
+ 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')
}
}
)
}
}
)