admin管理员组文章数量:1414930
I was looking around for my question but to no avail. I wanted to know if there was a way to force a worker to terminate a worker thread even if its task hadn't been pleted. I have some code in there that calls itself if it somehow fails, which is intentional even though it might be bad code practice. I tried using libraries such as microjob and threads, but those didn't have what I wanted. Here is what I tried to do with threads but didn't work:
// Module part of threads (taskModule)
expose(async function startTask(taskData, profileData, taskID) {
await _Task.FetchData(taskData);
await _Task.GenerateSession(profileData);
await _Task.RequestPermission(taskID);
await _Task.SubmitOrder();
return "finished";
})
// Runs the module (main.js)
const {spawn, Thread, Worker} = require("threads");
let task = null;
async function test() {
task = await spawn(new Worker('./taskModule'))
startTask({},{},"0")
}
setTimeout(async function() {
await Thread.terminate(task)
}, 3000)
test().then(() => {
console.log('hello')
}).catch(console.error)
I was trying to test to see if the code would stop after 3 seconds to test, but it seems like it just continues. Is there a better way to do this type of task?
Thanks for any help.
本文标签: javascriptIs there a way to force terminate a worker thread in nodejsStack Overflow
版权声明:本文标题:javascript - Is there a way to force terminate a worker thread in node.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745188321a2646788.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论