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 869e62a8bf718020c155ae221b85921735a61d74..a53857c0f311a63ff321b4ce08b9e1ef02465dcd 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,10
+1,15
@@
-import { join } from 'path'
+import { dirname, join } from 'path'
+import { fileURLToPath } from 'url'
import type { MyData, MyResponse } from './worker'
import type { MyData, MyResponse } from './worker'
-import { DynamicThreadPool, FixedThreadPool } from 'poolifier'
+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: Error) => {
console.error(e)
{
errorHandler: (e: Error) => {
console.error(e)
@@
-16,9
+21,9
@@
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
)
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: Error) => {
console.error(e)
{
errorHandler: (e: Error) => {
console.error(e)