这是indexloc提供的服务,不要输入任何密码
Skip to content

thread无法中断 #336

@wenghongtian

Description

@wenghongtian
function runTask(task: TaskType<CustomTask>, isAbort: () => boolean) {
  return new Promise<void>((resolve, reject) => {
    try {
      const thread = threads.start(() => {
        eval(task.taskData.content.jsConfig.content);
      });
      // const execution = engines.execScript(
      //   task.id,
      //   task.taskData.content.jsConfig.content,
      // );
      sleep(2000);
      setInterval(() => {
        if (isAbort()) {
          console.log("任务结束");
          thread.interrupt();
          // execution.getEngine().forceStop();
          resolve();
        }
      }, 1000);
    } catch (e) {
      reject(e);
    }
  });
}

task.taskData.content.jsConfig.content为js代码,里面有个无限循环
调用thread.interrupt()后,eval中的代码还在跑。

求大佬解答

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐞 故障Confirmed bugs or reports that are very likely to be bugsFeedback Awaited 🕒 等待反馈Waiting for the feedback from issue creater and issue will be closed if duration is over one monthMore Info Needed 🔎 提供详情Further information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions