repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge dependabot/npm_and_yarn/mocha-10.5.0 into combined-prs-branch
[poolifier.git]
/
examples
/
typescript
/
pool.ts
diff --git
a/examples/typescript/pool.ts
b/examples/typescript/pool.ts
index c55c4e96557dc8fcb400847745b0ac2c5ee014c7..1be0691a7aa7bf42423530d25d82994e4ce7fa6e 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-4,7
+4,7
@@
import { fileURLToPath } from 'node:url'
import {
availableParallelism,
DynamicThreadPool,
import {
availableParallelism,
DynamicThreadPool,
- FixedThreadPool
+ FixedThreadPool
,
} from 'poolifier'
import type { MyData, MyResponse } from './worker.js'
} from 'poolifier'
import type { MyData, MyResponse } from './worker.js'
@@
-14,33
+14,37
@@
const workerFile = join(
`worker${extname(fileURLToPath(import.meta.url))}`
)
`worker${extname(fileURLToPath(import.meta.url))}`
)
-
export
const fixedPool = new FixedThreadPool<MyData, 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, 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()
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(async () => {
await fixedPool.destroy()