andywer / andywer/threads.js

Debugging with ts-node and VS code

Đang mở
#274 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
help wanted question
Ngôn ngữ chính
TypeScript
Star
3.5k
Fork
173
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

There seems to be an issue with running threads.js with `node -r ts-node/register`.
Description of how the issue appears:
Launching application through VS Code debugger that has threads.js method call that spawns a new worker.
After the first call to such method, everything works fine - worker returns. Subsequent calls throws
```
Error: Timeout: Did not receive an init message from worker after 10000ms. Make sure the worker calls expose().
at Timeout._onTimeout (E:\something\node_modules\threads\dist\master\spawn.js:34:53)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
```

Details:
tsconfig.json
```
{
"compilerOptions": {
"skipLibCheck": true,
"lib": [
"dom",
"es5",
"es6",
"es7",
"es2015",
"es2016",
"es2017",
"es2018",
"esnext"
],
"module": "commonjs",
"moduleResolution": "node",
"pretty": true,
"sourceMap": false,
"target": "es6",
"outDir": "./dist",
"baseUrl": "./",
"declaration": true,
},
"forceConsistentCasingInFileNames": false,
"noImplicitReturns": true,
"noImplicitAny": true,
"strict": true,
"strictNullChecks": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"noUnusedLocals": false,
"esModuleInterop": true,
"typeRoots": [
"./node_modules/@types",
"./src/@types"
]
},
"include": [
"./src/*.ts",
"./src/**/*.ts",
"./src/**/*.d.ts"
],
"exclude": [
"node_modules"
],
"typeAcquisition": {
"enable": true
}
}
```
vs code debuggers launch.json
```
{
"version": "0.2.0",
"configurations": [
{
"name": "API",
"type": "node",
"request": "launch",
"args": [
"${workspaceFolder}/src/Server.ts"
],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart",
}
]
}
```
Sample code
Controller with the worker method
```
export default class Controller {
worker_pool: WorkerPool.Pool>
constructor() {
this.story_worker_pool = Pool(() => spawn(new Worker("./worker.worker")))
}
async method() {
return this.worker_pool.queue(async worker => {
processed_items = await worker.processItems(items)
})
}
}
```
worker
```
export class Worker implements WorkerModule {
[x: string]: WorkerFunction;

public processItems(items): any[] {
items.map((story, index) => {
// do math
});
return items
}
}
expose(Worker as any)
```
How this issue could be resolved? Everything works fine with the sample code after building the source code and running it with node

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.