repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
docs: refine CHANGELOG.md
[poolifier.git]
/
examples
/
typescript
/
pool.ts
diff --git
a/examples/typescript/pool.ts
b/examples/typescript/pool.ts
index 50dcc7b779d7118b27f42c56136fca509d58a7f6..54b437ab31b2f1d7785439c5ce9007167e554331 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,23
+1,34
@@
-import { DynamicThreadPool, FixedThreadPool } from 'poolifier'
-import { MyData, MyResponse } from './worker'
-
import { join } from 'path'
import { join } from 'path'
+import type { MyData, MyResponse } from './worker'
+import {
+ DynamicThreadPool,
+ FixedThreadPool,
+ availableParallelism
+} from 'poolifier'
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
-
8
,
+
availableParallelism()
,
join(__dirname, 'worker.js'),
{
join(__dirname, 'worker.js'),
{
- errorHandler: e => 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
,
+
Math.floor(availableParallelism() / 2)
,
+
availableParallelism()
,
join(__dirname, 'worker.js'),
{
join(__dirname, 'worker.js'),
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('Worker is online')
+ errorHandler: (e: Error) => {
+ console.error(e)
+ },
+ onlineHandler: () => {
+ console.info('Worker is online')
+ }
}
)
}
)