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 8e7d4bb7fd981c3bc1e01b80e716374e70187c53..54b437ab31b2f1d7785439c5ce9007167e554331 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,22
+1,34
@@
-import { join } from "path";
-import { DynamicThreadPool, FixedThreadPool } from "poolifier";
-import { MyData, MyResponse } from "./worker";
+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
,
- join(__dirname,
"worker.js"
),
+
availableParallelism()
,
+ 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
,
- join(__dirname,
"worker.js"
),
+
Math.floor(availableParallelism() / 2)
,
+
availableParallelism()
,
+ 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')
+ }
}
}
-)
;
+)