repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build(deps-dev): bump eslint from 9.4.0 to 9.5.0
[poolifier.git]
/
examples
/
typescript
/
pool.ts
diff --git
a/examples/typescript/pool.ts
b/examples/typescript/pool.ts
index 93774422b4500459715ec236c136c1601f13add4..1be0691a7aa7bf42423530d25d82994e4ce7fa6e 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,40
+1,52
@@
-import { dirname, extname, join } from 'path'
-import { fileURLToPath } from 'url'
-import type { MyData, MyResponse } from './worker'
+import { dirname, extname, join } from '
node:
path'
+import { fileURLToPath } from '
node:
url'
+
import {
import {
+ availableParallelism,
DynamicThreadPool,
FixedThreadPool,
DynamicThreadPool,
FixedThreadPool,
- availableParallelism
} from 'poolifier'
} from 'poolifier'
+import type { MyData, MyResponse } from './worker.js'
+
const workerFile = join(
dirname(fileURLToPath(import.meta.url)),
`worker${extname(fileURLToPath(import.meta.url))}`
)
const workerFile = join(
dirname(fileURLToPath(import.meta.url)),
`worker${extname(fileURLToPath(import.meta.url))}`
)
-
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>
>(
+
const fixedPool = new FixedThreadPool<MyData, MyResponse
>(
availableParallelism(),
workerFile,
{
availableParallelism(),
workerFile,
{
+ onlineHandler: () => {
+ console.info('Worker is online')
+ },
errorHandler: (e: Error) => {
console.error(e)
},
errorHandler: (e: Error) => {
console.error(e)
},
- onlineHandler: () => {
- console.info('Worker is online')
- }
}
)
}
)
-export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
+await fixedPool.execute()
+
+const dynamicPool = new DynamicThreadPool<MyData, MyResponse>(
Math.floor(availableParallelism() / 2),
availableParallelism(),
workerFile,
{
Math.floor(availableParallelism() / 2),
availableParallelism(),
workerFile,
{
+ onlineHandler: () => {
+ console.info('Worker is online')
+ },
errorHandler: (e: Error) => {
console.error(e)
},
errorHandler: (e: Error) => {
console.error(e)
},
- onlineHandler: () => {
- console.info('Worker is online')
- }
}
)
}
)
+
+await dynamicPool.execute()
+
+// eslint-disable-next-line @typescript-eslint/no-misused-promises
+setTimeout(async () => {
+ await fixedPool.destroy()
+ await dynamicPool.destroy()
+}, 3000)