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-server-pool/express-hybrid...
[poolifier.git]
/
examples
/
typescript
/
pool.ts
diff --git
a/examples/typescript/pool.ts
b/examples/typescript/pool.ts
index be92f73bf763afbe7b408ae5c5026c44b6ec3c2b..93774422b4500459715ec236c136c1601f13add4 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,22
+1,40
@@
-import { join } from 'path'
-import {
DynamicThreadPool, FixedThreadPool } from 'poolifier
'
+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,
+ 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: () => console.log('Worker is online')
+ errorHandler: (e: Error) => {
+ console.error(e)
+ },
+ onlineHandler: () => {
+ 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: () => console.log('Worker is online')
+ errorHandler: (e: Error) => {
+ console.error(e)
+ },
+ onlineHandler: () => {
+ console.info('Worker is online')
+ }
}
)
}
)