@leafer/task 1.12.4 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/task",
3
- "version": "1.12.4",
3
+ "version": "2.0.1",
4
4
  "description": "@leafer/task",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/math": "1.12.4",
26
- "@leafer/debug": "1.12.4"
25
+ "@leafer/math": "2.0.1",
26
+ "@leafer/debug": "2.0.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.12.4"
29
+ "@leafer/interface": "2.0.1"
30
30
  }
31
31
  }
package/src/TaskItem.ts CHANGED
@@ -17,10 +17,11 @@ export class TaskItem implements ITaskItem {
17
17
 
18
18
  public isComplete: boolean
19
19
  public isCancel: boolean
20
+ public runing: boolean
20
21
 
21
22
  public canUse?: IFunction
22
23
 
23
- private task: IFunction
24
+ public task: IFunction
24
25
 
25
26
  constructor(task?: IFunction) {
26
27
  this.id = IncrementId.create(IncrementId.TASK)
@@ -29,9 +30,10 @@ export class TaskItem implements ITaskItem {
29
30
 
30
31
  async run(): Promise<void> {
31
32
  try {
32
- if (this.isComplete) return
33
+ if (this.isComplete || this.runing) return
34
+ this.runing = true
33
35
  if (this.canUse && !this.canUse()) return this.cancel()
34
- if (this.task && this.parent.running) await this.task()
36
+ if (this.task) await this.task()
35
37
  } catch (error) {
36
38
  debug.error(error)
37
39
  }
@@ -135,7 +135,7 @@ export class TaskProcessor implements ITaskProcessor {
135
135
 
136
136
  public stop(): void {
137
137
  this.isComplete = true
138
- this.list.forEach(task => { if (!task.isComplete) task.cancel() })
138
+ this.list.forEach(task => { if (!task.isComplete) task.run() })
139
139
  this.pause()
140
140
  this.empty()
141
141
  }
package/types/index.d.ts CHANGED
@@ -44,8 +44,9 @@ declare class TaskItem implements ITaskItem {
44
44
  time: number;
45
45
  isComplete: boolean;
46
46
  isCancel: boolean;
47
+ runing: boolean;
47
48
  canUse?: IFunction;
48
- private task;
49
+ task: IFunction;
49
50
  constructor(task?: IFunction);
50
51
  run(): Promise<void>;
51
52
  complete(): void;