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 3d9d9e6f482723cdb634e98bd02a9bbd46df3314..1be0691a7aa7bf42423530d25d82994e4ce7fa6e 100644
(file)
--- a/
examples/typescript/pool.ts
+++ b/
examples/typescript/pool.ts
@@
-1,40
+1,52
@@
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { dirname, extname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
-import type { MyData, MyResponse } from './worker'
+
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)