repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: more worker function -> task function renaming
[poolifier.git]
/
examples
/
typescript
/
pool.ts
diff --git
a/examples/typescript/pool.ts
b/examples/typescript/pool.ts
index 8e7d4bb7fd981c3bc1e01b80e716374e70187c53..a53857c0f311a63ff321b4ce08b9e1ef02465dcd 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,22
+1,35
@@
-import { join } from "path";
-import { DynamicThreadPool, FixedThreadPool } from "poolifier";
-import { MyData, MyResponse } from "./worker";
+import { dirname, join } from 'path'
+import { fileURLToPath } from 'url'
+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(fileURLToPath(import.meta.url)), '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(fileURLToPath(import.meta.url)), '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')
+ }
}
}
-)
;
+)