如果 worker 里面跑的是死循环的话,应该是无法超时的吧
qile222 opened this issue · 3 comments
qile222 commented
SUCHMOKUO commented
@lolBig 是的,本来就是在主线程跑的
Jinbo008 commented
好厉害,搜了半天发现中文了。有个类似的问题,一块在这咨询下了哈。 (为了globalization,还是英语提问吧)
@SUCHMOKUO ,
I have a relate issue,
Issue :
timeout can't terminate threads when there's setInterval/setTimeout in worker threads.
- If I enabled next ①, then I can recevie timeout as expected,
- if I disabled next ①, there's no timeout , but worker indeed is running (as you can see ②)
Do you know how to force stop threads after timeout ?
Demo:
//hello module:
exports.world = function(value) {
console.info("[hello] input:%d" , value);
const process = require('process');
setInterval( ()=>{ // **②**
console.log("[hello]thread exist :%d", process.uptime());
//while(1);
},2000)
//while(1); // **①** (only for test)
return 1
}
// main threads:
const { DynamicPool, isTimeoutError } = require('node-worker-threads-pool');
const dynamicPool = new DynamicPool(4);
let mymodule = require('./service/hello')
dynamicPool.exec({
task: mymodule['world'],
param: 1,
timeout: 5000
}).then( (result,) => {
console.log("hello return:"+result);
}).catch ( (err) => {
if (isTimeoutError(err)) {
console.log("---> task timeout !")
}
})