andywer / andywer/threads.js

Working around ERR_PACKAGE_PATH_NOT_EXPORTED

Open
#326 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.5k
Forks
173
PR merge metrics
No merged PRs in 30d

Description

I'm trying to print your default thread size for a dry run purpose (without initialising a pool first).

```js
let {
dryRun,
threads = require('threads/dist/master/implementation').defaultPoolSize,
// ...
} = argv;

if (dryRun) {
console.log('threads', threads);
}
```

I'm having trouble updating to the latest version because of ERR_PACKAGE_PATH_NOT_EXPORTED. My workaround is:

```js
let {
dryRun,
threads,
// ...
} = argv;

let pool = Pool(() => spawn(new Worker('foo')), ...[threads].filter(Boolean));

if (dryRun) {
console.log('threads', pool.workers.length);
}
```

It works, but the original was more elegant. I know your implementation is simple and based on `cpus().length`, but I'd prefer not diverge from your default and start guessing wrong. What are your thoughts? Should a default config be exposed? If my workaround is what you recommend, feel free to close this issue. Thanks.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.