Browse Source

执行任务及监听进度 异步

哆啦好梦 2 years ago
parent
commit
3db7245210
1 changed files with 11 additions and 9 deletions
  1. 11 9
      electron/controller/example.js

+ 11 - 9
electron/controller/example.js

@@ -686,11 +686,10 @@ class ExampleController extends Controller {
     let jobId = args.id;
     let jobId = args.id;
     if (args.type == 'timer') {
     if (args.type == 'timer') {
       let myjob = new ChildJob();
       let myjob = new ChildJob();
+      
+      // 执行任务及监听进度
       let timerTask = myjob.exec('./jobs/example/timer', {jobId});
       let timerTask = myjob.exec('./jobs/example/timer', {jobId});
-
-      // 监听任务进度
       const channel = 'controller.example.timerJobProgress';
       const channel = 'controller.example.timerJobProgress';
-
       timerTask.emitter.on('job-timer-progress', (data) => {
       timerTask.emitter.on('job-timer-progress', (data) => {
         Log.info('[main-process] timerTask, from TimerJob data:', data);
         Log.info('[main-process] timerTask, from TimerJob data:', data);
 
 
@@ -698,12 +697,15 @@ class ExampleController extends Controller {
         event.reply(`${channel}`, data)
         event.reply(`${channel}`, data)
       })
       })
       
       
-      // myjob.on('job-timer-progress', (data) => {
-      //   Log.info('[main-process] myjob, from TimerJob data:', data);
-
-      //   // 发送数据到渲染进程
-      //   event.reply(`${channel}`, data)
-      // })
+      // 执行任务及监听进度 异步
+      // myjob.execPromise('./jobs/example/timer', {jobId}).then(task => {
+      //   task.emitter.on('job-timer-progress', (data) => {
+      //     Log.info('[main-process] timerTask, from TimerJob data:', data);
+
+      //     // 发送数据到渲染进程
+      //     event.reply(`${channel}`, data)
+      //   })
+      // });
     }
     }
     
     
     return;
     return;